From 5219fccff4ecb4507870bf59e353b0f1c30ea321 Mon Sep 17 00:00:00 2001 From: al Date: Mon, 14 Oct 2024 10:44:46 -0500 Subject: [PATCH 1/2] Update loops-practice.js think I finally got the loops concept --- assignment/scripts/loops-practice.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/assignment/scripts/loops-practice.js b/assignment/scripts/loops-practice.js index b4761fdd..b73d7c10 100644 --- a/assignment/scripts/loops-practice.js +++ b/assignment/scripts/loops-practice.js @@ -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'); From 803121f4da03d40798ee00bc6c85033669ed9025 Mon Sep 17 00:00:00 2001 From: al cotton Date: Thu, 31 Oct 2024 15:18:32 -0500 Subject: [PATCH 2/2] committing --- .DS_Store | Bin 0 -> 6148 bytes loops-practice.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .DS_Store create mode 100644 loops-practice.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bc0ccb61241db2107cb74346f7256f90c07a9cb0 GIT binary patch literal 6148 zcmeHK%SyvQ6rHJ6TZ_M_;3xPy zdgh_D)Pk#`a! zV{Me_Of)%uqXO#Ptuc=!_=RlZ{rSVB??=){|BK&`!X&L$-*|2*zr3;vlvZ!ut{l3l zmkyGK_js*Z7g9$4XWjEJ!}hRM-Z+tQ>V^9N(VCy5&!LM&;YNMV&qO zUiSJXke|+r>&a%*YEXFh&klBi*W>xI!H;A6-O2IQe~&;4kOHK@LKU#n&Lu-Gwv9sk`y2XrWIH+&9d76aR-`r|DR5x7AZgq{3``` zzUej_n3COFXC|liS^>L*DX6&2@K*{ddMie(+KRVe8t@BM0Xvp6!|(uf5YRGEK?*EX Ffe#C|YUTg{ literal 0 HcmV?d00001 diff --git a/loops-practice.js b/loops-practice.js new file mode 100644 index 00000000..12413e28 --- /dev/null +++ b/loops-practice.js @@ -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');