From e590285e82d92e0c553d76cfb06c6eb8cb203420 Mon Sep 17 00:00:00 2001 From: Gabbytam Date: Thu, 27 Aug 2020 19:41:11 -0700 Subject: [PATCH 1/2] Worked out loop problems on repl.it and copy&pasted it into a solutions txt --- gabbytam_solution.txt | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 gabbytam_solution.txt diff --git a/gabbytam_solution.txt b/gabbytam_solution.txt new file mode 100644 index 0000000..d315ab3 --- /dev/null +++ b/gabbytam_solution.txt @@ -0,0 +1,91 @@ +//Problem set: https://github.com/Gabbytam/JS-Basic-Loops + + +// 1. Get Even + +for(i=0; i<=200; i++){ + if(i%2===0){ + console.log(i); + } +} + +//2. Excited Kitten + +i=1; +while(i<=10){ + console.log('Love me, pet me! HSSSSSS!'); + let phrases= ["...human...why you taking pictures of me?...", "...the catnip made me do it...", "meow?", "...why does the red dot always get away..."]; + let randNum= Math.floor(Math.random()*4); + if(i%2===0){ + console.log(phrases[randNum]); + } + i++; +} + +//3. Thermostat + +let currentTemp= Math.floor(Math.random()*100)+1; +const desiredTemp= 68; + +console.log('The current temp is '+ currentTemp + 'F'); +while(currentTemp desiredTemp){ + currentTemp--; + console.log('The current temperature is now ' + currentTemp + 'F'); +} + +// 4. FizzBuzz + +for(let i=1; i<=100; i++){ + if(i%3===0){ + console.log("Fizz"); + } + if(i%5===0){ + console.log("Buzz"); + } + if(i%3===0 && i%5===0){ + console.log("FizzBuzz"); + } else { + console.log(i); + } +} + + +//Bonus +var phoneBook = { + "Abe": "111-111-1111", + "Bob": "222-222-2222", + "Cam": "333-333-3333", + "Dan": "444-444-4444", + "Ern": "555-555-5555", + "Fry": "111-111-1111", + "Gil": "222-222-2222", + "Hal": "333-333-3333", + "Ike": "444-444-4444", + "Jim": "555-555-5555", + "Kip": "111-111-1111", + "Liv": "222-222-2222", + "Mia": "333-333-3333", + "Nik": "444-444-4444", + "Oli": "555-555-5555", + "Pam": "111-111-1111", + "Qiq": "222-222-2222", + "Rob": "333-333-3333", + "Stu": "444-444-4444", + "Tad": "555-555-5555", + "Uwe": "111-111-1111", + "Val": "222-222-2222", + "Wil": "333-333-3333", + "Xiu": "444-444-4444", + "Yam": "555-555-5555", + "Zed": "111-111-1111" +} + +for(var thing in phoneBook){ + if(phoneBook[thing]==='333-333-3333'){ + console.log(thing); + } +} \ No newline at end of file From 66ea46e6497e7e278f85a4e32901ba4ad61d2902 Mon Sep 17 00:00:00 2001 From: Gabbytam Date: Thu, 27 Aug 2020 19:45:24 -0700 Subject: [PATCH 2/2] Wanted to add notes about a for...in loop --- gabbytam_solution.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gabbytam_solution.txt b/gabbytam_solution.txt index d315ab3..e44bb3e 100644 --- a/gabbytam_solution.txt +++ b/gabbytam_solution.txt @@ -84,7 +84,9 @@ var phoneBook = { "Zed": "111-111-1111" } +//thing refers to key for(var thing in phoneBook){ + //__objectname__[thing] refers to the value if(phoneBook[thing]==='333-333-3333'){ console.log(thing); }