Skip to content
Open
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
40 changes: 27 additions & 13 deletions assignment/scripts/loops-practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,50 @@ 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 (i);
}

// 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=3: i<6; i++) {
console.log (i);
}
// 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?
console.log('count even numbers from 2 to 10 (2, 4, 6, 8, 10):');
for (let i=2; i <=22; i+=2) {
console.log('Count', i);
]

// 1.d. (STRETCH) TODO: Write a for loop to do a countdown from 5 to 0
console.log('STRETCH: countdown from 5 to 0');
function countdown(5)
for (let i=5;(duration =0; cc--)
countdown timer =5
console.log('countdown')


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

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


const stars = ['Polaris', 'Gacrux', 'Formalhaut', 'Rigel', 'Deneb']
for(let i=5;(i<stars.length i++) {
console.log(stars[i])
}

// 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:');

const stars= 'Polaris', 'Gacrux', 'Formalhaut', 'Rigel', 'Deneb']
// 3.b. TODO: Write a while loop to console.log the numbers from 0 to 5
console.log('count from 0 to 5');
let index=0
let var=5
while ( var>=const) index<=[5]
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('count backwards from 10 to 5');
while i<=10
console.log('count backwards from 10 to 5');