Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
26 changes: 19 additions & 7 deletions assignment/scripts/loops-practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,48 @@ for (let i=0; i<4; i++) {

// 1.a. TODO: Write a for loop to console.log the numbers from 0 to 5
// - Which part of the example loop do you need to change to do this?
console.log('count from 0 to 5');
for (let i=0; i<6); i++ {
console.log('count from 0 to 5');
}

// 1.b. TODO: Write a for loop to console.log the numbers from 3 to 5
// - Which part of the example loop do you need to change to do this?
console.log('count from 3 to 5');
for (let i=2; i<6; i++ {
console.log('count from 3 to 5');
}

// 1.c. TODO: Write a for loop to console.log EVEN numbers from 2 to 10
// - Which part of the example loop do you need to change to do this?
for (let i=2; i<=10; +-2 {
console.log('count even numbers from 2 to 10 (2, 4, 6, 8, 10):');
}

// 1.d. (STRETCH) TODO: Write a for loop to do a countdown from 5 to 0
console.log('STRETCH: countdown from 5 to 0');

for (let i<6; i=0; --5 {
console.log('STRETCH: countdown from 5 to 0');
}

// 2. For of loops
console.log('---- 2. For Of loop ----');
let stars = ['Polaris', 'Gacrux', 'Formalhaut', 'Rigel', 'Deneb']

// 2.a. TODO: Write a for of loop to console.log each star in the 'stars' array
console.log('Some stars:');

for (let i=0; i<=5; i++ {
coconnsole.log('Some stars:');
}

// 3. While loops
console.log('---- 3. While loop ----');

// 3.a. TODO: Write a while loop to console.log each star in the 'stars' array
console.log('Some stars using while:');

console.log(let i>=0; while loop 4)
console.log('Some stars using while:)

// 3.b. TODO: Write a while loop to console.log the numbers from 0 to 5
console.log(let i>=0; while loop 6)
console.log('count from 0 to 5');

// 3.c. TODO: Write a while loop to console.log the numbers from 10 to 5
console.log(let i <=10; while loop 5)
console.log('count backwards from 10 to 5');
66 changes: 66 additions & 0 deletions loops-practice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
console.log('****** Loops Practice *******');


// 1. 'for' loop
console.log('---- 1. For loops ----');
// Example: a for loop to console.log numbers from 0 to 3
console.log('count from 0 to 3');
// start i at 0, while i is < 4 do code between {}, afterwards add 1 to i (i++)
for (let i=0; i<4; i++) {
console.log('count from 0 to 3:');
}

// 1.a. TODO: Write a for loop to console.log the numbers from 0 to 5
// - Which part of the example loop do you need to change to do this?
for (let i=0; i<6; i++) {
console.log('count from 0 to 5');
}

// 1.b. TODO: Write a for loop to console.log the numbers from 3 to 5
// - Which part of the example loop do you need to change to do this?
for (let i=3; i<6; i++)
console.log('count from 3 to 5');

// 1.c. TODO: Write a for loop to console.log EVEN numbers from 2 to 10
// - Which part of the example loop do you need to change to do this?
for (let i=2; i<11; i+-2) {
console.log('count even numbers from 2 to 10 (2, 4, 6, 8, 10):');
}
// 1.d. (STRETCH) TODO: Write a for loop to do a countdown from 5 to 0
for (let i=5; i>-1; i--) {
console.log('STRETCH: countdown from 5 to 0');
}

// 2. For of loops
let stars = ['Polaris', 'Gacrux', 'Formalhaut', 'Rigel', 'Deneb']
for (let star of stars) {
i>=0; i<=4; i+-
console.log(star);
}


// 2.a. TODO: Write a for of loop to console.log each star in the 'stars' array
for (let i=0; i<5; i++) {
console.log('stars[i]');
}
// 3. While loops
while (i<5) {
i>=0; i<=4; i+-
cobsole.log('stars[i]');
}
console.log('----3. while loops ----');

// 3.a. TODO: Write a while loop to console.log each star in the 'stars' array
while (i<5)
i>=0; i<=4; i+-
console.log('Some stars using while:');

// 3.b. TODO: Write a while loop to console.log the numbers from 0 to 5
while (i<6)
i>=0; i<=5; i+-
console.log('count from 0 to 5');

// 3.c. TODO: Write a while loop to console.log the numbers from 10 to 5
while (i>4)
i>=10; i>4; i--
console.log('count backwards from 10 to 5');