-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.js
More file actions
188 lines (87 loc) · 5.03 KB
/
Copy pathmain.js
File metadata and controls
188 lines (87 loc) · 5.03 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
=======================================================
** Week 2 - Project 1 **
Below are a number of problems for you to solve
using JS. The JS code can be written below each
problem.
=======================================================
*/
// 0. Connect the main.js document to the HTML page.
/* Add to the bottom of the HTML page: <script src="main.js"></script>*/
document.getElementById("q0").innerHTML = "JS Page Connected Properly!";
document.getElementById("q0").classList.add("status-good");
// 1. Output each item in the following Array to your console within their own paragraphs:
var livingRoom = ['couch', 'lamp', 'rug', 'shelf'];
// 2. Using a loop, log numbers 22-33 within their own paragraphs.
// 3. Using a similar loop, log numbers 75 to 100, only in increments of five.
// 4. Write a while loop that displays paragraphs of "This is how a professional loops." to the HTML page 5 times.
// 5. Separately, use both a for loop and while loop to do the same thing.
// Display in unique paragraphs the sentence "At home, I have _____ cats."
// The numbers should range from 10 to 110, in increments of 25.
// 6. Given the following Array, display in unique paragraphs'Even' if the number is even, 'Even and greater than 10' if the
// number is even and greater than 10, and 'Odd' if the number is odd.
// HINT: Google 'remainder operator'
var numArray = [2, 17, 9, 24, 8];
// 7. Using the following Array, create variable called numThrees with the value [13, 23, 33, 43, 53, 63, 73]
var numArray = [13, 15, 17, 23, 25, 27, 33, 35, 37, 43, 45, 47, 53, 55, 57, 63, 65, 67, 73, 75, 77];
// 8. Write a loop that outputs the following to unique paragraphs:
// #
// ##
// ###
// ####
// #####
// ######
// #######
// 9. FIZZ BUZZ
// Write a program that uses console.log to print each number up to 100, with a couple exceptions...
// If the number is divisible by 3, print "Fizz" instead of the number.
// If the number is divisible by 5, print "Buzz" instead of the number.
// If the number is divisible by both 3 and 5, print "FizzBuzz" instead of the number.
// RO SHAM BO!
// We're going to create a paper, rock, scissors game that prompts you for your choice and allows the computer to
// randomly choose. You will use an alert to define the winner.
// 10. Use a variable called "human" to prompt the user to type their choice.
// 11. Define a variable called "computer" and use Math.random to allow the computer to randomly select a number.
// For reference:
// Math.random gives you a random number between 0 and 1, which is different each time you call it.
// 12. Let's start our conditional statement.
// If the random computer number falls between 0 and .33, the computer is "rock"
// If the random computer number falls between .34 and .66, the computer is "paper"
// If the random computer number falls between .67 and 1, the computer is "scissors"
// 13. Using both "human" and the computer choice, begin another conditional statement to compare them.
// 14. After comparing, determine who has won; the computer or the human!
// 15. Give yourself a high five for completing your first javascript game!
// BONUS: What happens if your user enters something other than "rock", "paper", or "scissors?". Change your default case
// to print a snarky message to the console if the input doesn't match any of the options.
// ADVANCED TRACK
// 16. Write a conditional statement to find the largest of the numbers in the array provided.
var largestNum = [-5, -2, -6, 0, -1]
// HEADS OR TAILS?
// 17. Use the following variable for your coin flip action:
var coin = Math.floor(Math.random() * 2);
// We're using Math.random again, along with Math.floor.
// Remember, Math.random gives you a random number between 0 and 1.
// Calling Math.floor on that number will truncate the decimal, and give you a
// random number within the bounds of your array. (In this case, our array will only contain two items.)
// 18. Use a do/while loop to keep flipping the coin until you get tails.
// CHESS BOARD
// 19. Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines.
// At each position of the grid there is either a space or a “#” character. The characters should form a chess board.
//Passing this string to console.log should show something like this:
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// 20. When you have a program that generates this pattern, define a variable size = 8 and change the program
// sso that it works for any size, outputting a grid of the given width and height.
/* SANDBOX TRACK
Solving all of these problems is a great step in the right direction,
but the next step is coming up with your own arrangements to solve
new problems. Practice creating your own problems to solve and their solutions -
you can even challenge your classmates!
Also, consider how you can add/remove CSS styles to create added presentation with the results.
*/