-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathskillTestLoopsConditions.html
More file actions
175 lines (135 loc) · 4.62 KB
/
skillTestLoopsConditions.html
File metadata and controls
175 lines (135 loc) · 4.62 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WDV221 Intro Javascript</title>
<style>
section#buttons p {
text-indent:30px;
}
form#highLowForm {
width:500px;
margin-left:30px;
}
form#accumulateNumberForm {
width:500px;
margin-left:30px;
}
</style>
<script>
//Use with Exercise 3.
let classes = ["WDV101 Intro HTML and CSS","WDV131 Intro Photoshop","WDV150 E-Commerce","WDV221 Intro Javascript","WDV151 Intro Web Design"];
//Use with Exercise 5.
function displayColor(inColor)
{
alert("You selected the color " + inColor);
}
//Use with Exercise 6.
/*
The page should create a random number from 1-10 for use in the game.
If the player guess is less than the targetNumber display "Higher" in the result.
if the player guess is more than the targetNumber display "Lower" in the result.
If the player guess is the same display "Congratulations that is the number!"
*/
let numberToGuess = Math.round(Math.random() * (10 - 1) + 1);
console.log(numberToGuess)
function highLowGame()
{
var inValue = parseInt( document.getElementById("inputGuess").value ); //get value from the form
if (inValue == numberToGuess)
{
document.getElementById("highLowResult").innerHTML = "Congratulations! That is the number.";
}
else
{
if (inValue < numberToGuess) {
document.getElementById("highLowResult").innerHTML = "Higher.";
}
else{
document.getElementById("highLowResult").innerHTML = "Lower";
}
}
}
function resetHighLowGame()
{
document.getElementById("highLowForm").reset();
document.getElementById("highLowResult").innerHTML = "";
}
</script>
</head>
<body>
<h1>WDV221 Intro Javascript</h1>
<h2>Skill Test - Loops and Conditions</h2>
<h2>Includes Math Operators, If Statements, Loops and Arrays </h2>
<h3>Instructions:</h3>
<p>1. Write a run time For Loop that will display 1-5. Each number should be within a <p>.</p>
<script>
for (let index = 1; index <= 5; index++) {
document.write("<p>" + index + "</p>")
}
</script>
<p>2. Write a run time While Loop that will display 2-10. Each number should be within a <p>.</p>
<script>
let i = 2
while (i <=10 && i >=2) {
document.write("<p>" + i + "</p>")
i++
}
</script>
<p>3. Fix the following loop. It should display 5 items. </p>
<script>
for(k=0; k<classes.length; k++)
{
document.write("<p>" + classes[k] + "</p>");
}
</script>
<p>4. Change the following loop to include the line number on each output.</p>
<script>
var lineNumber=0;
while(lineNumber < 5)
{
document.write("<p>Line number " + (lineNumber + 1) + "</p>");
lineNumber++;
}
</script>
<p>5. Fix the last button to work like the others.</p>
<section id="buttons">
<p><input type="button" name="button4" id="button4" value="Display Blue" onClick="displayColor('Blue')"></p>
<p><input type="button" name="button4" id="button4" value="Display Green" onClick="displayColor('Green')"></p>
<p><input type="button" name="button4" id="button4" value="Display Red" onclick="displayColor('Red')"></p>
</section>
<p>6. Finish the function for the High-Low game. </p>
<form name="highLowForm" id="highLowForm" method="post" action="">
<fieldset>
<legend>High Low Game</legend>
<p>
<label>Input a number from 1-10
<input type="text" name="inputGuess" id="inputGuess">
</label>
</p>
<p>Result! <span id="highLowResult"></span></p>
<p>
<input type="button" name="makeGuess" id="makeGuess" value="Make a Guess">
<input type="button" name="resetHighLowGame" id="resetHighLowGame" value="Reset">
</p>
<script>
document.getElementById("makeGuess").addEventListener("click",highLowGame); //assign click event to form button
document.getElementById("resetHighLowGame").addEventListener("click",resetHighLowGame);
</script>
</fieldset>
</form>
<p>7. Use the array classes[] and Javascript to complete the following drop down box. </p>
<p>
<label>Select Your Class
<select name="selectClass" id="selectClassName">
<option>Select Class</option>
<script>
for (let x = 0; x < classes.length; x++) {
document.getElementById("selectClassName").innerHTML += ("<option>" + classes[x] + "</option>");
}
</script>
</select>
</label>
</p>
</body>
</html>