GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaScript-fundamentals-notes/loopArrayTasks.js at main · SMarsh-git/JavaScript-fundamentals-notes

Expand file tree

/

loopArrayTasks.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
119 lines (103 loc) · 2.64 KB
/

loopArrayTasks.js

Copy path

File metadata and controls

119 lines (103 loc) · 2.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Activity 1 //
let favFilm = [
"The Grand Budapest Hotel",
"The Shining",
"Shawshank Redemption",
"Godfather Part I",
"Goodfellas"
]
favFilm.push("The Grinch", "Falling Down");
for(let i = 0; i <favFilm.length; i++){
console.log(favFilm[i])
}
// Activity 2 //
for (let i=1; i<=6; i++){
console.log(Math.floor(Math.random() * 51));
}
// Activity 3 //
let count=[];
for (let i=9; i>=0; i--){
count.push(i);
}
console.log(`9-0 countdown is : ${count}.`)
// Activity 4 //
let favFilms = [
"The Grand Budapest Hotel",
"The Shining",
"Ghostbusters",
"Godfather Part I",
]
for (let i = 0; i <favFilms.length; i++){
console.log(favFilms[i])
}
if (favFilms[2]=='Ghostbusters'){
console.log ("YAY ITS GHOSTBUSTERS!")}
else{
console.log ("BOO! WE WANT GHOSTBUSTERS!")
}
// Activity 5 //
for (let i=1; i<=6; i++){
console.log(Math.floor(Math.random() * 31))
if ([i]%7==0){
console.log(`[${i}] is divisible by 7.`)
}
else {
console.log(`${i} is not divisible by 7.`)
}
}
for (let i = 0; i < 6; i++) {
const number = Math.round(Math.random() * 30);
if (number % 7 === 0) {
console.log(`${number} is divisible`);
}
else {
console.log(`${number} is not divisible `)
}
}
// Activity 6 //
let hannahsFollowers = [' Adam', ' Gary', ' Sam', ' Theo'];
let bobsFollowers = [' Adam', ' Sam', ' Gary', ' Peter'];
let mutualFollowers = [];
for (let i = 0; i < hannahsFollowers.length; i++) {
for (let j = 0 ; j < bobsFollowers.length; j++) {
if (hannahsFollowers[i] === bobsFollowers[j]){
mutualFollowers.push(bobsFollowers[j]);
}
}
}
console.log(`Your Mutual Followers are ${mutualFollowers[0]}, ${mutualFollowers[1]}, ${mutualFollowers[2]}.`);
// Activity 7 //
//Research on do...while loop, find out about the difference between for loop, while loop and do...while loop. Give examples of each. Pros and Cons
//EXAMPLE OF FOR LOOP
for (let i=0; i < 5; i++){
if (i=5)
console.log("I can count to 5!")
}
//EXAMPLE OF A WHILE LOOP
let n = 0;
let x = 0;
while (n < 5) {
n++;
x += n;
console.log(n)
}
console.log("I can count to five!")
//EXAMPLE OF do...while loops
//syntax
// do
// statement
// while (condition);
let result = '';
let i = 0;
do {
i = i + 1;
result = result + i;
} while (i < 5);
console.log(result);
// expected result: "12345"
let n=0
while (n < 5) {
n++;
console.log(n);
}
console.log("I can count to five!")
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.