From e61ba73488ecf33756c3c4990b0fda4e3b34c8fd Mon Sep 17 00:00:00 2001 From: AnaMz11 Date: Fri, 28 Aug 2020 20:08:10 -0700 Subject: [PATCH] added solutions to JS-Basic-Loops --- AnaMunozSolution.txt | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 AnaMunozSolution.txt diff --git a/AnaMunozSolution.txt b/AnaMunozSolution.txt new file mode 100644 index 0000000..9aaa24e --- /dev/null +++ b/AnaMunozSolution.txt @@ -0,0 +1,91 @@ +// 1. GET EVEN + +for(var i = 0; i <202; i+=2) { // will add plus 2 + console.log(i) +} + + +// // 2. Excited Kitten + // PART 1 +for(var i = 1; i<=10; i++) { + console.log('Love me, pet me! HSSSSSS!') +} + +//PART 2 + +//array + kittens = ['human why you take pictures','the catnip made me do it', 'meow?', 'why does the red dot always get away'] +// function loop every even pull and array at random + for (var i = 1; i <= 10; i++) { + console.log('Love me, pet me! HSSSSSS!') + if (i % 2 === 0) { + let randomChoice = Math.floor(Math.random()*4) // will iterate in all 4 strings in array... any higher will get undefined lower will will not pull all 3 + console.log(kittens[randomChoice])//why is randomChoice in [] + } + } + + //3 Thermostat + + currentTemp = Math.floor(Math.random()*101); + const desiredTemp = 78; // PG&E say this is the more efficient! :) + + console.log('The current temperature is', desiredTemp +'F') + while (currentTemp < desiredTemp) { + currentTemp++; + console.log('The temp is now', + currentTemp + 'F'); +} + while (currentTemp > desiredTemp) { + currentTemp--; + console.log('The temp is lower', + currentTemp + 'F'); +} + + +// 4 FIZZ BUZZ + +for (var i = 1; i<100; i++){ + if (i % 3 === 0 && i % 5 === 0) { + console.log("FizzBuzz") + } else if ( i % 3 ===0) { + console.log("Fizz") + } else if (i % 5 === 0) { + console.log("Buzz") + } 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 person in phoneBook) { + if(phoneBook[person] === "333-333-3333"){ + console.log(person)} + }