From 4ac8e31c2c040787a2b8015a0888ef9491386b1a Mon Sep 17 00:00:00 2001 From: Chris Corbin Date: Tue, 14 Jul 2020 14:33:48 -0700 Subject: [PATCH 1/5] Final (Pre-Stretch) --- index.js | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 73f240372..b05f04e2d 100644 --- a/index.js +++ b/index.js @@ -1,33 +1,52 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) +let votingAge = 18; +let age = 39; +if (age > 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 yourSpeed = 'Youre going Too Fast!'; +let speed = 50; +if(speed <= 55){ + yourSpeed = 'Your speed is Perfect! No ticket for you!'; +} +console.log(yourSpeed); //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method +Number('1999'); - - +console.log(Number('1999')); //Task d: Write a function to multiply a*b +function multiply(a,b){ + return a * b; +} - +console.log(multiply(13,3)); /************************************************************** 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 dogYears(age){ + return(age * 7); +} +console.log(dogYears(39)); @@ -49,7 +68,29 @@ // 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 dogFood(weight, age){ + if(age >= 1){ + if(weight <= 5){ + return(weight * .05); + }else if (weight <= 10){ + return(weight * .04); + }else if (weight <= 15){ + return(weight * .03); + }else if (weight > 15){ + return(weight * .02); + } + }else if(age < 1){ + if(weight > 2){ + return(weight * .10); + }else if (weight > 4){ + return(weight * .05); + }else if (weight > 7){ + return(weight * .04); + } +} +} + +console.log(dogFood(15, 1)); @@ -60,20 +101,59 @@ // 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 rps(rpsChoice){ + if(rpsChoice = 'rock'){ + user = 0; + } + if(rpsChoice = 'paper'){ + user = 1; + } + if(rpsChoice = 'scissors'){ + user = 2; + } + + let computer = Math.floor(Math.random()*3); + + if(user === computer){ + return('You Tie...'); + } else if(user === 0,computer === 2){ + return('You Win!'); + } else if(user === 0,computer === 1){ + return('You Lose.'); + } else if(user === 1,computer === 0){ + return('You Win!'); + } else if(user === 1,computer === 2){ + return('You Lose.'); + } else if(user === 2,computer === 1){ + return('You Win!'); + } else if(user === 2,computer === 0){ + return('You Lose.'); + } + +} + +console.log(rps('scissors')); /************************************************************** Task 5 **************************************************************/ //Metric Converter //a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles +function kmToM(km){ + return(km * 0.621371 + ' Miles'); +} +console.log(kmToM(42)); //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters +function ftTocm(feet){ + return(feet * 30.48 + ' Centimeters'); +} +console.log(ftTocm(6)); @@ -82,6 +162,16 @@ // 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(sodaBottles){ + for (let sb = sodaBottles; sb >= 1; sb--){ + console.log(sb + ' bottles of soda on the wall... ' + sb + ' bottles of soda... take one down pass it around... ' + (sb - 1) + ' bottles of soda on the wall.'); + if(sb <= 1){ + return('Now theres no more soda bottles on the wall, go home!'); + } + } +} + +console.log(annoyingSong(7)); @@ -95,7 +185,21 @@ //60s should be D //and anything below 60 should be F - +function letterGrade(input){ + if(input > 90){ + return('You got an A!'); + }else if(input > 80){ + return('You got an B.'); + }else if(input > 70){ + return('You got an C.'); + }else if(input > 60){ + return('You got an D.'); + }else if(input < 60){ + return('You got an F!'); + } +} + +console.log(letterGrade(59)); From 1e7edb4e92bb590bc750035e62e2082a38ecd222 Mon Sep 17 00:00:00 2001 From: Chris Corbin Date: Tue, 14 Jul 2020 15:05:21 -0700 Subject: [PATCH 2/5] Final (Pre-Stretch) vocab edits --- index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b05f04e2d..094899476 100644 --- a/index.js +++ b/index.js @@ -129,7 +129,6 @@ function rps(rpsChoice){ } else if(user === 2,computer === 0){ return('You Lose.'); } - } console.log(rps('scissors')); @@ -189,17 +188,17 @@ function letterGrade(input){ if(input > 90){ return('You got an A!'); }else if(input > 80){ - return('You got an B.'); + return('You got a B.'); }else if(input > 70){ - return('You got an C.'); + return('You got a C.'); }else if(input > 60){ - return('You got an D.'); + return('You got a D.'); }else if(input < 60){ - return('You got an F!'); + return('You got a F!'); } } -console.log(letterGrade(59)); +console.log(letterGrade(81)); From a6956985838c4e539a87a9219e36e300db12ec3a Mon Sep 17 00:00:00 2001 From: Chris Corbin Date: Tue, 14 Jul 2020 16:01:10 -0700 Subject: [PATCH 3/5] Final + Stretch for Rock, Paper, Scissors --- index.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 094899476..a802b021a 100644 --- a/index.js +++ b/index.js @@ -215,7 +215,36 @@ console.log(letterGrade(81)); //Take Rock, Paper, Sissors further //update your rock papers sissors code below to take a prompt from a user using the window object +let rppsChoice = window.prompt('Do you choose rock, paper, or scissors?: '); +alert('You chose ' + rppsChoice + ' !'); +function rpps(rppsChoice){ + if(rppsChoice = 'rock'){ + user = 0; + } + if(rppsChoice = 'paper'){ + user = 1; + } + if(rppsChoice = 'scissors'){ + user = 2; + } + let computer = Math.floor(Math.random()*3); - + if(user === computer){ + console.log('You Tie...'); + } else if(user === 0,computer === 2){ + console.log('You Win!'); + } else if(user === 0,computer === 1){ + console.log('You Lose.'); + } else if(user === 1,computer === 0){ + console.log('You Win!'); + } else if(user === 1,computer === 2){ + console.log('You Lose.'); + } else if(user === 2,computer === 1){ + console.log('You Win!'); + } else if(user === 2,computer === 0){ + console.log('You Lose.'); + } +} +result = rpps(rppsChoice); \ No newline at end of file From 6db431e8c76fb253c8283cb108bbc6369308acb5 Mon Sep 17 00:00:00 2001 From: Chris Corbin Date: Tue, 14 Jul 2020 16:21:26 -0700 Subject: [PATCH 4/5] Minor Edits --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a802b021a..361819ee5 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 = 18; -let age = 39; +let age = 38; if (age > 18){ } @@ -46,7 +46,7 @@ function dogYears(age){ return(age * 7); } -console.log(dogYears(39)); +console.log(dogYears(38)); From 20cc994249d886eaf9f428d278d6dc94ba4df1e4 Mon Sep 17 00:00:00 2001 From: Chris Corbin Date: Tue, 14 Jul 2020 16:23:29 -0700 Subject: [PATCH 5/5] Minor Edits --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 361819ee5..156ef3f84 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ function multiply(a,b){ return a * b; } -console.log(multiply(13,3)); +console.log(multiply(19,2)); /************************************************************** Task 2 **************************************************************/