Skip to content

Commit e11b518

Browse files
authored
Update Person.cdc
1 parent a5534c7 commit e11b518

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

cadence/contracts/Person.cdc

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
1-
// A simple Person contract
1+
// A simple Person contract
22
//
33
// reference: https://developers.flow.com/cadence/language/contracts
44
pub contract Person {
55
// declaration of a public variable
66
pub var name: String
77
// declaration of a private variable, reference: https://developers.flow.com/cadence/language/access-control#access-control
8-
access(self) var mood: Mood
9-
10-
// Enums type declaration, reference: https://developers.flow.com/cadence/language/enumerations#enum-declaration
11-
pub enum Mood: UInt8 {
12-
pub case happy
13-
pub case angry
14-
pub case melanholic
15-
}
8+
access(self) var happy: Bool
169

1710
// initialization method for our contracts, this gets run on deployment
1811
init() {
1912
self.name = "Alice"
20-
self.mood = Mood.happy
13+
self.happy = true
2114
}
2215

2316
pub fun hello(): String {
2417
log("saying hello") // when we log we can see the log in the emulator output, helpful for debugging
2518
26-
switch self.mood {
27-
case Mood.happy:
28-
return "😍 Hello!"
29-
case Mood.angry:
30-
return "😤 Go away!"
31-
case Mood.melanholic:
32-
return "😐 Hi I guess?"
33-
default:
34-
return "💩 Not sure!"
35-
}
19+
return self.happy == true ? "😍 Hello!" : "😤 Go away!"
3620
}
3721

3822
pub fun WhoAmI(): String {
3923
return "I am ".concat(self.name)
4024
}
4125

42-
// set a new name
43-
pub fun setName(name: String) {
44-
self.name = name
26+
pub fun changeMyMood() {
27+
self.happy = !self.happy
4528
}
4629

30+
// create a new friendship resource
31+
pub fun makeFriends(): @Friendship {
32+
return <-create Friendship()
33+
}
34+
4735
// Friendship resource are types of values that can only exist in one place
4836
//
4937
// read more about this unique and powerful Cadence feature here https://developers.flow.com/cadence/language/resources
5038
pub resource Friendship {
51-
39+
pub var strength: UInt64
40+
41+
init() {
42+
self.strength = unsafeRandom()
43+
}
5244
}
53-
54-
}
45+
}
5546

5647

48+

0 commit comments

Comments
 (0)