From 0f7c44aacd4146c0a13a096c2dede91c342a40ba Mon Sep 17 00:00:00 2001 From: kai-blt Date: Mon, 7 Sep 2020 14:31:26 -0700 Subject: [PATCH 1/9] Answered task a & b --- index.html | 2 +- index.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index d49e1b2a0..955e540ae 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,6 @@ Document - + \ No newline at end of file diff --git a/index.js b/index.js index 73f240372..ff78120d8 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,19 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) - - - +let votingAge = 35; +if (votingAge > 18) { + console.log('true'); +} //Task b: declare a variable and then use a conditional to change the value of that variable based on the value assigned to a second variable (no function required) +let varA = 'variable a'; +let varB = 'variable b'; - - +if (varA !== varB) { + varA = varB; + console.log(varA); +} //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method From e92d7ed1e42991761f6edb8b60217c65463cc971 Mon Sep 17 00:00:00 2001 From: kai-blt Date: Mon, 7 Sep 2020 14:38:33 -0700 Subject: [PATCH 2/9] answered tasks c & d --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ff78120d8..298dbe455 100644 --- a/index.js +++ b/index.js @@ -12,18 +12,23 @@ let varB = 'variable b'; if (varA !== varB) { varA = varB; - console.log(varA); + console.log('varB assigned to varA: ' + varA); } //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method - - +console.log('Converted string to number: ' + Number('1999')); //Task d: Write a function to multiply a*b +function multiply(a,b) { + return a*b; +} +console.log('Regular Function: ' + multiply(2,5)); +let multiplyArrow = (a,b) => a * b; +console.log('Arrow Function: ' + multiplyArrow(5,2)); From 40d5bcdf1a27495745ebe3fedce40bf5aa0dc9ee Mon Sep 17 00:00:00 2001 From: kai-blt Date: Mon, 7 Sep 2020 14:56:37 -0700 Subject: [PATCH 3/9] completed tasks 2 & 3 --- index.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 298dbe455..82173224f 100644 --- a/index.js +++ b/index.js @@ -36,8 +36,10 @@ console.log('Arrow Function: ' + multiplyArrow(5,2)); /************************************************************** Task 2 **************************************************************/ //Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years - - +function toDogYears(age) { + return age * 7; +} +console.log('35 to dog years: ' + toDogYears(35)); @@ -58,7 +60,26 @@ console.log('Arrow Function: ' + multiplyArrow(5,2)); // 7 - 12 months 4% of their body weight // when you are finished invoke your function with the weight of 15 lbs and the age of 1 year - if your calculations are correct your result should be 0.44999999999999996 - +function dogFoodCalculator(weight, age) { + if (age < .4 ) { + return weight * .1; + } else if ((age > .4 && age < .7)) { + return weight * .05; + } else if ((age > .7 && age < 1)) { + return weight * .04; + } else { + if (weight < 5) { + return weight * .05; + } else if (weight >= 6 && weight <= 10) { + return weight * .04; + } else if (weight >= 11 && weight <=15) { + return weight * .03; + } else { + return weight * .02; + } + } +} +console.log(dogFoodCalculator(15, 1)); From edd9de17c93fbafcd3ea945f32e7d47d5fa3528e Mon Sep 17 00:00:00 2001 From: kai-blt Date: Tue, 8 Sep 2020 07:48:59 -0700 Subject: [PATCH 4/9] Finished task 4, rock/paper/scissors --- index.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 82173224f..f64db9cba 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,54 @@ console.log(dogFoodCalculator(15, 1)); // use math.random to determine the computers choice // hint while you can complete this with only conditionals based on strings it may help to equate choice to a number - + +/*Function to choose a number for AI between the minimum and maximum number given. +It is inclusive, so it will include the lowest and highest value provided in the return.*/ +function aiChoice(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1) + min); +} + + + +function rockPaperScissors(playerChoice) { + /*Let ai choice be between 1 and 3. Result of 1 = rock, 2 = scissors, 3 = paper.*/ + let ai = aiChoice(1,3); + + switch (playerChoice) { + case 'rock': + if (ai === 1) { + console.log('Tie. Player: rock - AI: rock. Try again!') + } else if (ai === 2) { + console.log('Win. Player: rock - AI: scissors.') + } else { + console.log('Loss. Player: rock - AI: paper. Try again!') + } + break; + case 'paper': + if (ai === 1) { + console.log('Win. Player: paper - AI: rock.') + } else if (ai === 2) { + console.log('Loss. Player: paper - AI: scissors. Try again!') + } else { + console.log('Tie. Player: paper - AI: paper. Try again!') + } + break; + case 'scissors': + if (ai === 1) { + console.log('Loss. Player: scissors - AI: rock. Try again!') + } else if (ai === 2) { + console.log('Tie. Player: scissors - AI: scissors. Try again!') + } else { + console.log('Win. Player: scissors - AI: paper.') + } + break; + } +} + + + /************************************************************** Task 5 **************************************************************/ From beda2616a2e654cfd07110a980111e1b45263030 Mon Sep 17 00:00:00 2001 From: kai-blt Date: Tue, 8 Sep 2020 07:55:49 -0700 Subject: [PATCH 5/9] finished task 5 --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f64db9cba..6d7f5a60e 100644 --- a/index.js +++ b/index.js @@ -100,8 +100,6 @@ function aiChoice(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } - - function rockPaperScissors(playerChoice) { /*Let ai choice be between 1 and 3. Result of 1 = rock, 2 = scissors, 3 = paper.*/ let ai = aiChoice(1,3); @@ -137,6 +135,8 @@ function rockPaperScissors(playerChoice) { } } +/*Play the game*/ +rockPaperScissors('rock'); @@ -144,13 +144,15 @@ function rockPaperScissors(playerChoice) { /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles - +const kmToMiles = (km) => km * 0.621371; +console.log('100 km to mi is: ' + kmToMiles(100)); //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters - +const feetToCM = (feet) => feet * 30.48; +console.log('100 ft to cm is: ' + feetToCM(100)); From 565dcff75c628951c5d40ea073886f3ba16f6311 Mon Sep 17 00:00:00 2001 From: kai-blt Date: Tue, 8 Sep 2020 08:36:45 -0700 Subject: [PATCH 6/9] completed task 6 --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6d7f5a60e..629225d05 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,14 @@ console.log('100 ft to cm is: ' + feetToCM(100)); // 99 bottles of soda on the wall // create a function called annoyingSong // the function should take a starting number as an argument and count down - at each iteration it should log (number) bottles of soda on the wall, (number) bottles of soda, take one down pass it around (number left over) bottles of soda on the wall` - +function annoyingSong(number) { + for (i = number; i > 0; i--) { + console.log(i + ' bottles of soda on the wall, ' + i + ' bottles of soda, take one down pass it around ' + (i - 1) + ' bottles of soda on the wall.') + + } +} + +annoyingSong(10); From 41434d270c5d32e44fb494d525ed330755c6e4d7 Mon Sep 17 00:00:00 2001 From: kai-blt Date: Tue, 8 Sep 2020 08:59:59 -0700 Subject: [PATCH 7/9] completed task 7 --- index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 629225d05..0f9651aba 100644 --- a/index.js +++ b/index.js @@ -161,13 +161,14 @@ console.log('100 ft to cm is: ' + feetToCM(100)); // 99 bottles of soda on the wall // create a function called annoyingSong // the function should take a starting number as an argument and count down - at each iteration it should log (number) bottles of soda on the wall, (number) bottles of soda, take one down pass it around (number left over) bottles of soda on the wall` -function annoyingSong(number) { + +function annoyingSong(number) { for (i = number; i > 0; i--) { console.log(i + ' bottles of soda on the wall, ' + i + ' bottles of soda, take one down pass it around ' + (i - 1) + ' bottles of soda on the wall.') } } - +/*Play song*/ annoyingSong(10); @@ -181,7 +182,21 @@ annoyingSong(10); //70s should be Cs //60s should be D //and anything below 60 should be F - +function gradeCalc(grade) { + if (grade >= 90) { + console.log('Your grade is an A'); + } else if (grade >= 80 && grade < 90) { + console.log('Your grade is a B'); + } else if (grade >= 70 && grade < 80) { + console.log('Your grade is a c'); + } else if (grade >= 60 && grade < 70) { + console.log('Your grade is a D'); + } else { + console.log('Your grade is an F'); + } +} +/*Calculate Grades*/ +gradeCalc(100); From 93bd6fd7f8052dc86c31c11b99e87bb76f3f145e Mon Sep 17 00:00:00 2001 From: kai-blt Date: Tue, 8 Sep 2020 12:56:37 -0700 Subject: [PATCH 8/9] completed stretch goal --- index.js | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 0f9651aba..a4a1406df 100644 --- a/index.js +++ b/index.js @@ -107,36 +107,36 @@ function rockPaperScissors(playerChoice) { switch (playerChoice) { case 'rock': if (ai === 1) { - console.log('Tie. Player: rock - AI: rock. Try again!') + return 'Tie. Player: rock - AI: rock. Try again!' } else if (ai === 2) { - console.log('Win. Player: rock - AI: scissors.') + return 'Win. Player: rock - AI: scissors.' } else { - console.log('Loss. Player: rock - AI: paper. Try again!') + return 'Loss. Player: rock - AI: paper. Try again!' } break; case 'paper': if (ai === 1) { - console.log('Win. Player: paper - AI: rock.') + return 'Win. Player: paper - AI: rock.' } else if (ai === 2) { - console.log('Loss. Player: paper - AI: scissors. Try again!') + return 'Loss. Player: paper - AI: scissors. Try again!' } else { - console.log('Tie. Player: paper - AI: paper. Try again!') + return 'Tie. Player: paper - AI: paper. Try again!' } break; case 'scissors': if (ai === 1) { - console.log('Loss. Player: scissors - AI: rock. Try again!') + return 'Loss. Player: scissors - AI: rock. Try again!' } else if (ai === 2) { - console.log('Tie. Player: scissors - AI: scissors. Try again!') + return 'Tie. Player: scissors - AI: scissors. Try again!' } else { - console.log('Win. Player: scissors - AI: paper.') + return 'Win. Player: scissors - AI: paper.' } break; } } /*Play the game*/ -rockPaperScissors('rock'); +console.log(rockPaperScissors('rock')); @@ -163,9 +163,8 @@ console.log('100 ft to cm is: ' + feetToCM(100)); // the function should take a starting number as an argument and count down - at each iteration it should log (number) bottles of soda on the wall, (number) bottles of soda, take one down pass it around (number left over) bottles of soda on the wall` function annoyingSong(number) { - for (i = number; i > 0; i--) { + for (let i = number; i > 0; i--) { console.log(i + ' bottles of soda on the wall, ' + i + ' bottles of soda, take one down pass it around ' + (i - 1) + ' bottles of soda on the wall.') - } } /*Play song*/ @@ -184,19 +183,19 @@ annoyingSong(10); //and anything below 60 should be F function gradeCalc(grade) { if (grade >= 90) { - console.log('Your grade is an A'); + return 'Your grade is an A'; } else if (grade >= 80 && grade < 90) { - console.log('Your grade is a B'); + return 'Your grade is a B'; } else if (grade >= 70 && grade < 80) { - console.log('Your grade is a c'); + return 'Your grade is a c'; } else if (grade >= 60 && grade < 70) { - console.log('Your grade is a D'); + return 'Your grade is a D'; } else { - console.log('Your grade is an F'); + return 'Your grade is an F'; } } /*Calculate Grades*/ -gradeCalc(100); +console.log(gradeCalc(100)); @@ -206,6 +205,23 @@ gradeCalc(100); // Hint - you may need to study tomorrow's traning kit on arrays // try looking up the .includes() method +function countVowels(string) { + let count = 0; + let vowels = ['a','e','i','o','u']; + let stringLower = string.toLowerCase(); + let stringArray = stringLower.split(''); + + for (let i = 0; i < vowels.length; i++) { + for (let j = 0; j < stringArray.length; j++) { + if (stringArray[j] === vowels[i]) { + count++; + } + } + } + return 'There are ' + count + ' vowels in the word: ' + string; +} +console.log(countVowels('Test Vowels')); + From a4266829e0e7baa8ee21ac0a90497b6b4c05b123 Mon Sep 17 00:00:00 2001 From: kai-blt Date: Tue, 8 Sep 2020 13:02:21 -0700 Subject: [PATCH 9/9] finished stretch 2 --- index.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/index.js b/index.js index a4a1406df..d790a6aa0 100644 --- a/index.js +++ b/index.js @@ -230,7 +230,50 @@ console.log(countVowels('Test Vowels')); //Take Rock, Paper, Sissors further //update your rock papers sissors code below to take a prompt from a user using the window object +function aiChoice(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1) + min); +} +function rockPaperScissors(playerChoice) { + /*Let ai choice be between 1 and 3. Result of 1 = rock, 2 = scissors, 3 = paper.*/ + let ai = aiChoice(1,3); + + switch (playerChoice) { + case 'rock': + if (ai === 1) { + return 'Tie. Player: rock - AI: rock. Try again!' + } else if (ai === 2) { + return 'Win. Player: rock - AI: scissors.' + } else { + return 'Loss. Player: rock - AI: paper. Try again!' + } + break; + case 'paper': + if (ai === 1) { + return 'Win. Player: paper - AI: rock.' + } else if (ai === 2) { + return 'Loss. Player: paper - AI: scissors. Try again!' + } else { + return 'Tie. Player: paper - AI: paper. Try again!' + } + break; + case 'scissors': + if (ai === 1) { + return 'Loss. Player: scissors - AI: rock. Try again!' + } else if (ai === 2) { + return 'Tie. Player: scissors - AI: scissors. Try again!' + } else { + return 'Win. Player: scissors - AI: paper.' + } + break; + } +} + +/*Play the game*/ +let input = prompt('Please enter rock, paper or scissors'); +console.log(rockPaperScissors(input));