-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
201 lines (168 loc) · 7.63 KB
/
index.html
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
189
190
191
192
193
194
195
196
197
198
199
200
201
<html lang="en">
<head>
<script>
//Example function which takes parameters and returns something:
let power= (base,exp) =>
{
let res=1;
while (exp>0){
res*=base;
exp-=1;
}
return res;
}
let v=power(4,3);
alert (v);
let doIt=()=>{
x=document.getElementById("bw").value;
{
if(x>15)
{
alert ("Overweight");
}
}
}
//Exercise 2
let clickHere=()=>{
alert("Multiples");
// a=document.getElementById("multiples").value;
// {
let sum = 0;
for (a = 0; a <1000; a++)
{
if (a % 3 === 0 || a % 5 === 0)
{
sum += a;
}
}
alert("sum is " + sum);
// }
}
//Exercise 3
function Multiples(a, b, n) {
let sum = 0;
for (let i = 1; i < n; i++) {
if (i % a === 0 || i % b === 0) {
sum += i;
}
}
return sum;
}
function Click() {
let a = document.getElementById("a").value;
let b = document.getElementById("b").value;
let n = document.getElementById("n").value;
let result = Multiples(a, b, n);
alert("The sum of multiples of " + a + " or " + b + " below " + n + " is: " + result);
}
//Exercise 4
function sumOfMultiples(a, b, l) {
let arrays = [];
let sum = 0;
for (let i = 1; i <= l; i++) {
if (i % a === 0 || i % b === 0) {
arrays.push(i);
sum += i;
}
}
return sum;
}
function Click1() {
let a = document.getElementById("a").value;
let b = document.getElementById("b").value;
let l = document.getElementById("l").value;
let result = sumOfMultiples(a, b, l);
alert("The sum of multiples of " + a + " or " + b + " up to " + l + " is: " + result);
}
//example6
let mapNums1=()=>{
let s=document.getElementById("nums").value;
strArray=s.split(" ")
nArray=[]
for(let i=0; i<strArray.length;i++){
nArray.push(parseInt(strArray[i]));
}
squares=[]
for(let i=0; i<nArray.length;i++){
squares.push(nArray[i]*nArray[i]);
}
for(let i=0; i<squares.length;i++){
alert(squares[i]);
}
}
</script>
</head>
<body>
<p>This is body text</p>
<p>Hello World!</p>
<p>Excerise 1:</p>
<p>Create a page with a button and input. This should prompt the user for their baggage weight.</p>
<p>When the user clicks submit,</p>
<p>If the weight is over the limit of 15kgs, it should alert the user that the bag is overweight.</p>
<p>The prompt:<input type ="text" id="bw" ,width= "6"><button onclick="doIt()">The button Text(Submit Maybe?)</button></p>
<p>Exercise 2:</p>
<p>Create a page with a button</p>
<p>When the user clicks,</p>
<p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.</p>
<p>Find the sum of all the multiples of 3 or 5 below 1000 and alert the user to the correct answer.</p>
<p>The prompt: <input type ="text" id= "multiples" ,width ="6"><button onclick="clickHere()">Press me!</button></p>
<p>Exercise 3, Functions:</p>
<p>Create a page with a button and three input boxes, labelled a, b and n</p>
<p>When the user clicks, </p>
<p>
<p>Create a function to return the sum of all the multiples of a or b below n</p>
<p>Call the function and alert the user to the correct answer when they press the button.</p>
</p>
<label>Enter value of a </label>
<input type="text" id="a" ><br>
<label>Enter value of b</label>
<input type="text" id="b"><br>
<label>Enter value of n</label>
<input type="text" id="n" ><br>
<p><button onclick="Click()">Press me!</button></p>
<p>Exercise 4, Arrays:</p>
<p>Exercise 4, Arrays: f4 should take 2 integer and 1 array parameters and return an integer.</p>
<p>Create a page with a button and three input boxes, labelled a, b and l, l should be a large input</p>
<p>Create a function to return the sum of all the multiples of a or b in l</p>
<p>Call the function and alert the user to the correct answer when they press the button.</p>
<p><a href="Example4.html">Example4</a></p>
</p>
<p>Exercise 5, Arrays:</p>
<p>Create a function f4 to return the sum of all the multiples of a or b in l</p>
<p>Call the function f4 in the function called by onClick, and alert the user to the
returned answer when they press the button.</p>
<p>Exercise 5, Arrays: f5 should take array parameters and return an integer.</p>
<p>Create a page with a button and two wide input boxes, labelled a and l</p>
<p>Create a function to return the sum of all the multiples of factors in a found in in l (a and l should be arrays of integers and a is of length 2)</p>
<p>Call the function and alert the user to the correct answer when they press the button.</p>
<p>Create a function f5 to return the sum of all the multiples of factors in a
found in in l (a and l should be arrays of integers, a is of length 2)</p>
<p>Call the function f5 in the function called by onClick, and alert the user to the
returned answer when they press the button.</p>
</p>
<p>You may find the split function useful for creating arrays from the strings entered: <a href="https://www.w3schools.com/jsref/jsref_split.asp">Split</a></p>
<p><a href="Example5.html">Example5</a></p>
<p>Exercise 6, Arrays:</p>
<p>Exercise 6, Arrays: f6 should take array parameters and return an integer.</p>
<p>Create a page with a button and two wide input boxes, labelled a and l</p>
<p>Create a function to return the sum of all the multiples of factors in a found in in l (a and l should be arrays of integers)</p>
<p>Call the function and alert the user to the correct answer when they press the button.</p>
<p>Create a function f6 to return the sum of all the multiples of factors in a
found in in l (a and l should be arrays of integers)</p>
<p>Call the function f6 in the function called by onClick, and alert the user to the
returned answer when they press the button.</p>
</p>
<p>You may find the split function useful for creating arrays from the strings entered: <a href="https://www.w3schools.com/jsref/jsref_split.asp">Split</a></p>
<p><a href="Example6.html">Example6</a></p>
<p>Exercise 7, Objects as dictionaries/hashtables:</p>
<p>Create a function, f7, that takes two parameters, basket and prices</p>
<p>f7 should compute the cost of the basket given the prices supplied.</p>
<p>basket should be an object holding product:quantity (string:int) pairs</p>
<p>prices should be an object holding product:price (string:float) pairs</p>
<p>====</p>
<p>Create a testing page for the function f7</p>
<p><a href="Example7.html">Example7</a></p>
<p><a href="Example7getvalue.html">Example7 Answer</a></p>
</body>
</html>