-
Notifications
You must be signed in to change notification settings - Fork 0
/
js_0601practice05_for_loop.html
112 lines (90 loc) · 2.33 KB
/
js_0601practice05_for_loop.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//0601_巢狀迴圈
//兩層迴圈
//畫星星
//input = 5 時
//1*****
//2****
//3***
//4**
//5*
//第一層input 5 =>5層
//步驟一
input = 5;
for(let i =0; i < 5; i++){
document.write(i);
for(let j = 0; i >=j; j++){
document.write(j);
}
document.write("<br>");
}
//步驟二
input = 5;
tmp = input;
for(let i =0; i < input; i++){
console.log('old tmp =>' + tmp);
tmp--; //tmp = tmp -1;
console.log('mew tmp =>' + tmp);
document.write(i);
for(let j =0; j <= tmp ; j++){
//document.write(j);
document.write('*');
}
document.write("<br>");
}
//for loop 星星練習3
//input = 5
//*****
//*****
//*****
//*****
//*****
//方法一
/*let input = 5;
for(let i = 0 ; i < input ; i++){
console.log(i + "*****");
document.write(i)
}*/
//方法二 *30
let input =5;
let inputJ = 30;
for(let i = 0 ; i < input ; i++){
// 1.蓋大樓
// document.write(i);
// 2.畫input數量的星星
for(let j = 0 ; j < inputJ ; j++){
// document.write(j);
document.write('*');
}
document.write('<br>');
}
//練習題
//for loop 星星練習
//input = 5
// *
// ***
//*****
//******
//********
sum = '';
input = 5;
for(let i = 0 ; i < input ; i++){
// sum = sum + '*';
sum += '*';
// console.log(`${i+1} => ${sum}`);
document.write(`${i+11} => ${sum} <br>`)
// document.write(`${i} => ${sum} <br>`)
// document.write(`${sum} <br>`)
}
</script>
</body>
</html>