-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex04.html
58 lines (44 loc) · 1.55 KB
/
ex04.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Exercicio #04</title>
</head>
<body>
<form name="formulario" onsubmit="return false">
<label>Digite um número: </label>
<input type="number" name="num"/>
<button onclick="ex04()">OK</button>
</form>
<script>
/*
Exercício #04:
Faca uma funcao que recebe uma inteiro n e a partir dele monta n divs de cores de fundo
alternados entre red, green, blue e yellow.
*/
function ex04(){
var num = document.forms.formulario.num.value;
for(var i=0; i<num; i++){
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
switch(i%4){
case 0:
div.style.backgroundColor = "red";
break;
case 1:
div.style.backgroundColor = "green";
break;
case 2:
div.style.backgroundColor = "blue";
break;
case 3:
div.style.backgroundColor = "yellow";
break;
}
document.body.appendChild(div);
}
}
</script>
</body>
</html>