-
Notifications
You must be signed in to change notification settings - Fork 0
/
work.txt
130 lines (98 loc) · 3.47 KB
/
work.txt
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// 1. Create two variables, firstCard and secondCard.
// Set their values to a random number between 2-11
let firstCard = getRandomCard();
let secondCard = getRandomCard();
// 2. Create a variable, sum, and set it to the sum of the two cards
let sum = firstCard + secondCard;
function getRandomCard() {
let randomNumber = Math.floor(Math.random() * 10) + 2;
return randomNumber;
}
let firstCard = 6
let secondCard = 9
let sum = firstCard + secondCard
console.log(sum)
---------------------
let firstCard = 10
let secondCard = 7
let sum = firstCard + secondCard
if (sum < 21 ){
console.log("Do you want to draw a new card?")
} else if (sum === 21){
console.log("Wohoo! You've got Blackjack!")
}else if (sum > 21){
console.log("You're out of the game!")
}
---------------------------------------------------------------------
// Check if the person is old enough to enter the nightclub (21)
// Log a suitable message to the console in both cases
let age = 22
// if less than 21 -> "You can not enter the club!"
// else -> "Welcome!"
if (age < 21) {
console.log("You can not enter the club!")
} else {
console.log("Welcome!")
}
----------------------------------------------------------------------
// Check if the person is elegible for a birthday card from the King! (100)
let age = 90
// if less than 100 -> "Not elegible"
// else if exactly 100 -> "Here is your birthday card from the King!"
// else -> "Not elegible, you have already gotten one"
if (age < 100) {
console.log("Not eligible");
} else if (age === 100) {
console.log("Here is your birthday card from the King!");
} else {
"Not elegible, you have already gotten one";
}
-----------------------------------------------------------------------------
let firstCard = 10;
let secondCard = 7;
let sum = firstCard + secondCard;
if (sum <= 20) {
console.log("Do you want to draw a new card? 🙂");
} else if (sum === 21) {
console.log("Wohoo! You've got Blackjack! 🥳");
} else {
console.log("You're out of the game! 😭");
}
-----------------------------------------------------------------------------
let firstCard = 10;
let secondCard = 11;
let sum = firstCard + secondCard;
let hasBlackJack = false;
let isAlive = true; // 1. Create a variable called isAlive and assign it to true
if (sum <= 20) {
console.log("Do you want to draw a new card? 🙂");
} else if (sum === 21) {
console.log("Wohoo! You've got Blackjack! 🥳");
hasBlackJack = true; // 2. Flip its value to false in the appropriate code block
} else {
console.log("You're out of the game! 😭");
isAlive = false; // 2. Flip its value to false in the appropriate code block
}
console.log(isAlive); // 3. Log it out to check that you're doing it right
-------------------------------------------------------------------------------------
Adding the message variable
let firstCard = 10
let secondCard = 4
let sum = firstCard + secondCard
let hasBlackJack = false
let isAlive = true
// 1. Declare a variable called message and assign its value to an empty string
let message = ""
// 2. Reassign the message variable to the string we're logging out
if (sum <= 20) {
message = "Do you want to draw a new card? 🙂"
} else if (sum === 21) {
message = "Wohoo! You've got Blackjack! 🥳"
hasBlackJack = true
} else {
message = "You're out of the game! 😭"
isAlive = false
}
// 3. Log it out!
console.log(message)
-----------------------------------------------------------------------------------