From c184127178914f8316dd7d002237fbc78f26745d Mon Sep 17 00:00:00 2001 From: al Date: Sun, 13 Oct 2024 13:34:41 -0500 Subject: [PATCH] Update loops-practice.js --- assignment/scripts/loops-practice.js | 40 +++++++++++++++++++--------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/assignment/scripts/loops-practice.js b/assignment/scripts/loops-practice.js index b4761fdd..14da790c 100644 --- a/assignment/scripts/loops-practice.js +++ b/assignment/scripts/loops-practice.js @@ -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=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');