-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx6.html
More file actions
36 lines (33 loc) · 857 Bytes
/
Copy pathEx6.html
File metadata and controls
36 lines (33 loc) · 857 Bytes
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
<DOCTYPE! html>
<html>
<head>
<title>Exercise 6</title>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
let choice = prompt("Take s for sum or m for multi");
if (choice === "s") {
var n = Number(prompt("Your number"));
let sum = 0;
for (i = 1; i <= n; i++) {
sum += i;
}
document.getElementById("demo").innerHTML = sum;
} else if (choice === "m") {
var n = Number(prompt("Your number"));
let mul = 1;
for (i = 1; i <= n; i++) {
mul *= i;
}
document.getElementById("demo").innerHTML = mul;
} else {
document.write("Wrong letter");
}
}
</script>
</body>
</html>
</DOCTYPE!>