-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditonalsArrayLoops.js
More file actions
115 lines (93 loc) · 4.23 KB
/
ConditonalsArrayLoops.js
File metadata and controls
115 lines (93 loc) · 4.23 KB
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
////////////
// ARRAYS //
////////////
console.log("Challenge #1:");
// Create an array called "roster" with the following names as
// strings: Pikachu, MewTwo, Onix, Eevee
// Console.log the length of the "roster" array
const Roster = ["Pikachu","MewTwo","Onix","Eevee"]
console.log(Roster);
// ==================================================================
console.log("Challenge #2:");
// push the user's first command line argument to the end of the
// "roster" array (ideally, it's a pokemon's name!)
// console.log the "roster" array
// ==================================================================
console.log("Challenge #3:");
// remove the item from the "roster" array that corresponds to
// the user's second command line argument
// NOTE: consider what data type command line arguments come in as
// console.log the "roster" array
//////////////////
// CONDITIONALS //
//////////////////
console.log("Challenge #4:");
// Create a variable called "catchChance" and set it equal to .25
// Note: this corresponds to a 25% chance to catch a pokemon!
// Create a variable called "catchAttempt" and set it equal to
// Math.random()
// Note: we'll learn more about Math.random() later, but for now
// just think of it as equal to a random decimal between 0 and 1
// If "catchAttempt" is less than "catchChance" console.log "Caught it!"
// Otherwise, console.log "Aargh! Almost had it!"
// ==================================================================
console.log("Challenge #5:");
// If the number of pokemon in the "roster" array is less than 6
// Add an empty string to the "roster" array (signifying an empty
// spot)
// Console.log the "roster" array
// ==================================================================
console.log("Challenge #6:");
const elements = ["plant","fire","water"];
const enemyAttackType = elements[Math.floor(Math.random()*elements.length)];
// You've been provided a variable called "enemyAttackType" that is a
// random string that can be "plant","fire",or "water".
// (assuming you have a "water" pokemon...)
// If the "enemyAttackType" is "plant", console.log "It's super effective!"
// Else if the "enemyAttackType" is "fire", console.log "It's not very effective!"
// Else if the "enemyAttackType" is "water", console.log "Nothing special happened!"
// Else console.log "Error, this isn't supposed to be seen!"
// NOTE: Look up how to code a "switch". Depending on the situation,
// "switch" is better than using "if/else if" statements.
///////////
// LOOPS //
///////////
console.log("Challenge #7:");
// Console.log the first and last letter of each string in the
// "roster" array
// ==================================================================
console.log("Challenge #8:");
// Console.log the average length of strings in the "roster" array
// ==================================================================
console.log("Challenge #9:");
const attackDmg = Math.floor(Math.random()*20);
// You've been provided a variable named "attackDmg" that is a random
// number.
// Create a variable called "health" and set it equal to 100;
// While "health" is above 0, subtract "attackDmg" from it and
// console.log(`Health is at: ${health}`);
// Hint: W3School While Loop : https://www.w3schools.com/jsref/jsref_while.asp
///////////
// BONUS //
///////////
console.log("Bonus #1:");
// Bonus #1:
// Console.log the sum of string lengths for all of the names in the
// "roster" array
// ==================================================================
console.log("Bonus #2:");
// Bonus #2:
// If the last string in the "roster" array is "Ditto",
// Console.log "console.log" ('cause it's Ditto...get it!?)
// else, console.log the last string in the "roster" array
// ==================================================================
console.log("Bonus #3:");
// Bonus #3:
const enemyRoster = ["Bulbasaur","Raichu","Onix","Bob","",""];
// You've been provided an array of strings called "enemyRoster"
// Create a new empty array called "outcome"
// For each item in the "roster" array, if the length of the item is
// greater or equal to the length of the corresponding indexed string
// in the "enemyRoster" array, then add "Win" to the "outcome" array.
// Otherwise, add "Loss" to the "outcome" array.
//Console.log the "outcome" array