-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_5.1.mo
28 lines (23 loc) · 912 Bytes
/
day_5.1.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
actor{
// Challenge 2
let favoriteNumber:HashMap.HashMap<Principal,Nat> = HashMap.HashMap<Principal,Nat>(0,Principal.equal,Principal.hash);
// Challenge 3 & 4
public shared(msg) func add_favorite_number(n:Nat):async Text{
let prinicipal = msg.caller;
if(not Option.isNull(favoriteNumber.get(prinicipal))){
return "You've already registered your number";
};
favoriteNumber.put(prinicipal,n);
return "You've successfully registered your number";
};
public shared(msg) func show_favorite_number():async ?Nat{
return favoriteNumber.get(msg.caller);
};
// Challenge 5
public shared({caller}) func update_favorite_number(n:Nat):async (){
favoriteNumber.put(caller,n);
};
public shared({caller}) func delete_favorite_number():async ?Nat{
return favoriteNumber.remove(caller);
};
}