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
93 changes: 93 additions & 0 deletions gabbytam_solution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//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++;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! you've simulated the functionality of a for loop with a while loop. pretty cool! 😄


//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');
}
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);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check this. 15 is getting caught in the fizz section.

the main idea here is to put the most specific condition first, as fewer of the numbers will get caught in it. so, lines 49-50 should be first, and the check against 3 and the check against 5 can happen after that



//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"
}

//thing refers to key
for(var thing in phoneBook){
//__objectname__[thing] refers to the value
if(phoneBook[thing]==='333-333-3333'){
console.log(thing);
}
}