From d437096e799c4708e9ec8a555afdc6eebf0c9798 Mon Sep 17 00:00:00 2001 From: IsaacGHoward Date: Fri, 21 Aug 2020 11:28:52 -0700 Subject: [PATCH 1/4] Task 1 a-d completed --- index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 73f240372..ae60177a7 100644 --- a/index.js +++ b/index.js @@ -1,26 +1,33 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) - +let votingAge = 21; +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 variable1 = 10; +if(votingAge > variable1) + variable1 = votingAge - 18; +console.log(variable1); //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method - +console.log(Number("1999")); //Task d: Write a function to multiply a*b - - +function mult(num1, num2){ + return(num1*num2); +} +console.log(mult(3,5)); /************************************************************** Task 2 **************************************************************/ From 6be2bcf561c7a20a16610d2393a1fa03b698b772 Mon Sep 17 00:00:00 2001 From: IsaacGHoward Date: Fri, 21 Aug 2020 12:06:42 -0700 Subject: [PATCH 2/4] Completed Tasks 2 - 4. Made console.logs easier to read --- index.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index ae60177a7..dca823eeb 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) let votingAge = 21; if(votingAge > 18) - console.log(true); + console.log("Task 1A : " + true); @@ -11,14 +11,14 @@ if(votingAge > 18) let variable1 = 10; if(votingAge > variable1) variable1 = votingAge - 18; -console.log(variable1); +console.log("Task 1B : " + variable1); //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method -console.log(Number("1999")); +console.log("Task 1C : Convert '1999' to integer : " + Number("1999")); @@ -27,13 +27,17 @@ console.log(Number("1999")); function mult(num1, num2){ return(num1*num2); } -console.log(mult(3,5)); +console.log("Task 1D : Multiply 3 * 5 : " + mult(3,5)); /************************************************************** 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(humanYears){ + return(humanYears*7); +} +console.log("Task 2 : 5 Human Years To Dog Years : " + toDogYears(5)); @@ -55,7 +59,29 @@ console.log(mult(3,5)); // 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 dogFeeder(weight, age){ + if(age >= 1){ + if(weight <= 5) + return(.05 * weight); + else if(weight <= 10) + return(.04 * weight); + else if(weight <= 15) + return(.03 * weight); + else + return(.02 * weight); + } + else{ + let months = age * 12; + if(months >= 2 || months <= 4) + return(.1 * weight); + else if(months <= 7) + return(.05 * weight); + else if(months <= 12){ + return(.04 * weight); + } + } +} +console.log("Task 3 : " + dogFeeder(15,1)); @@ -66,9 +92,33 @@ console.log(mult(3,5)); // it should return you won or you lost based on the rules of the game (you may need to look up the rules if you have not played before) // 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 convertRPS(convertThis){ + if(convertThis === 0) + return("Rock"); + else if(convertThis === 1) + return("Paper"); + else if(convertThis === 2) + return("Scissors"); + else if(convertThis === "Rock") + return(0); + else if(convertThis === "Paper") + return(1); + else if(convertThis === "Scissors") + return(2); +} +function RPS(playerChoice){ + var computerChoice = Math.floor(Math.random() * 3); + playerChoice = convertRPS(playerChoice); + if(computerChoice - playerChoice === 1 || computerChoice - playerChoice === -2) + return(`You Lost ; ${convertRPS(computerChoice)} beats ${convertRPS(playerChoice)}`); + else if(computerChoice - playerChoice === 0) + return(`You Tied ; ${convertRPS(playerChoice)} and ${convertRPS(computerChoice)} are the same`); + else + return(`You Win ; ${convertRPS(playerChoice)} beats ${convertRPS(computerChoice)}`); +} +console.log("Task 4 : " + RPS("Rock")); - /************************************************************** Task 5 **************************************************************/ //Metric Converter From e4b813355bc5edb2c5e9a94be53c3a3b78525a06 Mon Sep 17 00:00:00 2001 From: IsaacGHoward Date: Fri, 21 Aug 2020 12:10:17 -0700 Subject: [PATCH 3/4] Finished Task 5 a-b --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index dca823eeb..1849c79c2 100644 --- a/index.js +++ b/index.js @@ -123,14 +123,18 @@ console.log("Task 4 : " + RPS("Rock")); /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles - - +function kilometersToMiles(km){ + return(km * .621371) +} +console.log("Task 5A : " + kilometersToMiles(10)); //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters - - +function feetToCentimeters(feet){ + return(feet * 30.48); +} +console.log("Task 5B : " + feetToCentimeters(20)); From 3a96b1b0fb5bc415f094a4c73f0c87fd674d2f48 Mon Sep 17 00:00:00 2001 From: IsaacGHoward Date: Fri, 21 Aug 2020 12:32:33 -0700 Subject: [PATCH 4/4] Task 6, 7 and Stretch goal --- index.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 1849c79c2..02273a51c 100644 --- a/index.js +++ b/index.js @@ -143,8 +143,15 @@ console.log("Task 5B : " + feetToCentimeters(20)); // 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(startPoint){ + var bottlesCount = startPoint; + while(bottlesCount > 0){ + console.log(`${bottlesCount} bottles of soda on the wall, ${bottlesCount} bottles of soda, take one down pass it around ${bottlesCount-1} bottles of soda on the wall`); + bottlesCount--; + } +} +console.log("Task 6 : vvv") +annoyingSong(3); /************************************************************** Task 7 **************************************************************/ @@ -156,17 +163,35 @@ console.log("Task 5B : " + feetToCentimeters(20)); //60s should be D //and anything below 60 should be F - - +function gradeCalc(numberGrade){ + if(numberGrade >= 90) + return("A"); + else if(numberGrade >= 80) + return("B"); + else if(numberGrade >= 70) + return("C"); + else if(numberGrade >= 60) + return("D"); + else + return("F"); +} +console.log("Task 7 : A 70 should be a " + gradeCalc(70)); /************************************************************** Stretch **************************************************************/ //Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels. // Hint - you may need to study tomorrow's traning kit on arrays // try looking up the .includes() method - - - +function vowelCount(theString){ + var splitString = theString.toLowerCase().split(''); + var numVowels = 0; + splitString.forEach(character => { + if(character.match(`a|e|i|o|u`)) + numVowels++; + }); + return(numVowels); +} +console.log("STRETCH : Vowel count for 'Hello There' is " + vowelCount("Hello There")); /************************************************************** Stretch **************************************************************/