- Notifications
You must be signed in to change notification settings - Fork 27.3k
/
Copy pathwhile.html
38 lines (28 loc) · 683 Bytes
/
while.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
<!DOCTYPE html>
<htmllang="en-US">
<head>
<metacharset="utf-8">
<metaname="viewport" content="width=device-width">
<title>Basic while loop example</title>
<style>
</style>
</head>
<body>
<p></p>
<script>
constcats=['Bill','Jeff','Pete','Biggles','Jasmin'];
letmyFavoriteCats='My cats are called ';
letpara=document.querySelector('p');
leti=0;
while(i<cats.length){
if(i===cats.length-1){
myFavoriteCats+=`and ${cats[i]}.`;
}else{
myFavoriteCats+=`${cats[i]}, `;
}
i++;
}
para.textContent=myFavoriteCats;
</script>
</body>
</html>