-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpro25.ts
88 lines (43 loc) · 2.1 KB
/
pro25.ts
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
//Alien Colors #1: Imagine an alien was just shot down in a game.
// Create a variable called alien_color and assign it a value of 'green', 'yellow', or 'red'.
/*• Write an if statement to test whether the alien’s color is green.
If it is, print a message that the player just earned 5 points.
• Write one version of this program that passes the if test and another that fails
. (The version that fails will have no output.)*/
let alien_Color = "green";
if (alien_Color == "green") {
console.log("Player just earned 5 points");
};
if (alien_Color == "red") {
console.log("no output");
}
// Question 26
/*Alien Colors #2: Choose a color for an alien as you did in Exercise 25, and write an if-else chain.
• If the alien’s color is green, print a statement that the player just earned 5 points for shooting the alien.
• If the alien’s color isn’t green, print a statement that the player just earned 10 points.
• Write one version of this program that runs the if block and another that runs the else block.
*/
if (alien_Color === "green") {
console.log("player just earned 5 points for shooting the alien");}
else{
console.log("player just earned 10 points");
}
if (alien_Color !== "green") {
console.log("player just earned 5 points for shooting the alien");}
else{
console.log("player just earned 10 points");
}
/*Alien Colors #3: Turn your if-else chain from Exercise 5-4 into an if-else chain.
• If the alien is green, print a message that the player earned 5 points.
• If the alien is yellow, print a message that the player earned 10 points.
• If the alien is red, print a message that the player earned 15 points.
• Write three versions of this program, making sure each message is printed for the appropriate color alien.*/
if (alien_Color === "green") {
console.log("the player earned 5 points");
}
if (alien_Color==="red") {
console.log("the player earned 15 points.");
}
if (alien_Color === "yellow"){
"the player earned 10 points."
}