From bdfa6a8297764ba466306c021341a80476547d83 Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Wed, 7 Sep 2022 12:53:18 -0600 Subject: [PATCH 1/9] wrote task 1 --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index e2ebbd6a5..0f4d1aa81 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,12 @@ Do the following: HINT: no function required */ +let votingAge=17 +if (votingAge=>18){ + console.log("True"); +} else{ + console.log("False"); +} From 27bf9de059e3c4c9ecdc734b7448437a541a5d01 Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Wed, 7 Sep 2022 13:09:03 -0600 Subject: [PATCH 2/9] true statement task 1 --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0f4d1aa81..c8e4246d6 100644 --- a/index.js +++ b/index.js @@ -19,11 +19,11 @@ Do the following: HINT: no function required */ -let votingAge=17 -if (votingAge=>18){ - console.log("True"); -} else{ +let votingAge=23; +if (votingAge<18){ console.log("False"); +} else{ + console.log("True"); } From 2350bc2105c4424397f34e8ca4ae0680ea5c3cd9 Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Wed, 7 Sep 2022 13:14:39 -0600 Subject: [PATCH 3/9] Task b done and passed --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c8e4246d6..9f2b5e6af 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,13 @@ Do the following: HINT: no function required */ - +let thingOne= 12; +let thingTwo=3; +if (thingOne===thingTwo){ + console.log("True"); +} else { + console.log("False") +} From 10bffb95a0ea7636393d4bb722f043ffbf748e0b Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Thu, 8 Sep 2022 01:41:27 -0600 Subject: [PATCH 4/9] passed 1C --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9f2b5e6af..983c29f42 100644 --- a/index.js +++ b/index.js @@ -61,7 +61,9 @@ Do the following: HINT: look up the Number method */ - +let numberC= "1999"; +numberC=== +1999; +console.log(numberC); /* From 24c409ec237ae7e6734d727c3a47b24c85539814 Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Sat, 10 Sep 2022 00:26:17 -0600 Subject: [PATCH 5/9] finished and passed task3 --- index.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 983c29f42..587981095 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,7 @@ Do the following: function multiply(num1, num2){ return num1 * num2; } - +console.log(multiply(12,3)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -91,10 +91,10 @@ Do the following: 3. Return the newly calculated age */ -function dogYears(/*add your code here*/){ - /*add your code here*/ +function dogYears(humanYear){ + return humanYear*7; } - +console.log(dogYears(33)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -111,6 +111,43 @@ HINT: Remember that the order in which we pass in our arguments matters when it Feeding Requirements: + +*/ +function hungryDog(dogAge, dogWeight){ + if (dogAge===1 || dogAge===2 || dogAge===3){ + let DFA= dogWeight*.1; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else if (dogAge===4 || dogAge===5 || dogAge===6 || dogAge===7){ + let DFA= dogWeight*.5; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else if (dogAge===8 || dogAge===9 || dogAge===10 || dogAge===11){ + let DFA= dogWeight*.04; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else if (dogAge===12, dogWeight===1 || dogWeight===2 || dogWeight===3 || dogWeight===4 || dogWeight===5){ + let DFA= dogWeight*.05; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else if (dogAge===12, dogWeight===6 || dogWeight===7 || dogWeight===8 || dogWeight===9 || dogWeight===10){ + let DFA= dogWeight*.04; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else if (dogAge===12, dogWeight===11 || dogWeight===12 || dogWeight===13 || dogWeight===14 || dogWeight===15){ + let DFA= dogWeight*.03; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else if (dogAge===12){ + let DFA= dogWeight*.02; + console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + } + else { + console.log("Keep trying Beckon"); + } +} +hungryDog(12,16); +/* Adult Dogs 1 year and older up to 5 lbs - 5% of their body weight 6 - 10 lbs - 4% of their body weight @@ -121,8 +158,17 @@ Puppies less than 1 year 2 - 4 months 10% of their body weight 4 - 7 months 5% of their body weight 7 - 12 months 4% of their body weight - -NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996 +const conditionsArray = [ + condition1, + condition2, + condition3, +] + +if (conditionsArray.indexOf(false) === -1) { + "do somthing" +} + +/*NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996 NOTE 2: This is a great time to check the tests to see what it expects, versus what is actually returned from your function. This is an example of the output to look for on each test point. ● hungryDogFunction › Dog is 1 year and is 5lbs or less @@ -143,9 +189,7 @@ NOTE 2: This is a great time to check the tests to see what it expects, versus w So, on this one test, the weight would be 4 pounds, and the age would be 1 years old. It's expecting your function to return a decimal number of 0.2 */ -function hungryDog(/*add your code here*/){ - /*add your code here*/ -} + From 6da01ce63a522e1ed1eaace1674d605cff9385f0 Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Wed, 21 Sep 2022 07:52:57 -0600 Subject: [PATCH 6/9] Tasks up to 5 completed. --- index.js | 117 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 49 deletions(-) diff --git a/index.js b/index.js index 587981095..81be9681c 100644 --- a/index.js +++ b/index.js @@ -112,41 +112,40 @@ HINT: Remember that the order in which we pass in our arguments matters when it Feeding Requirements: -*/ -function hungryDog(dogAge, dogWeight){ - if (dogAge===1 || dogAge===2 || dogAge===3){ - let DFA= dogWeight*.1; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); - } - else if (dogAge===4 || dogAge===5 || dogAge===6 || dogAge===7){ - let DFA= dogWeight*.5; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); - } - else if (dogAge===8 || dogAge===9 || dogAge===10 || dogAge===11){ - let DFA= dogWeight*.04; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); - } - else if (dogAge===12, dogWeight===1 || dogWeight===2 || dogWeight===3 || dogWeight===4 || dogWeight===5){ - let DFA= dogWeight*.05; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); - } - else if (dogAge===12, dogWeight===6 || dogWeight===7 || dogWeight===8 || dogWeight===9 || dogWeight===10){ - let DFA= dogWeight*.04; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); +*/ +function hungryDog(weight, age){ + if (age<0.34){ + let percent=0.1; + let DFA= weight*percent; + console.log(weight, age, percent, DFA); + return; } - else if (dogAge===12, dogWeight===11 || dogWeight===12 || dogWeight===13 || dogWeight===14 || dogWeight===15){ - let DFA= dogWeight*.03; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + else if (age <=.6 || age===1 && weight<=5){ + let percent=0.05; + let DFA= weight*percent; + console.log(weight, age, percent, DFA); + return; + } + else if (age <=.92 || age===1 && weight<=10){ + let percent=0.04; + let DFA= weight*percent; + console.log(weight, age, percent, DFA); + return; } - else if (dogAge===12){ - let DFA= dogWeight*.02; - console.log("At "+dogAge+" months and "+dogWeight+" pounds, give "+DFA+" pounds of food."); + else if (age===1 && weight<=15){ + let percent=0.03; + let DFA= weight*percent; + console.log(weight, age, percent, DFA); + return; } else { - console.log("Keep trying Beckon"); + let percent= 0.02; + let DFA= weight*percent; + console.log(weight, age, percent, DFA); + return; } } -hungryDog(12,16); +hungryDog(7,1); /* Adult Dogs 1 year and older up to 5 lbs - 5% of their body weight @@ -158,15 +157,6 @@ Puppies less than 1 year 2 - 4 months 10% of their body weight 4 - 7 months 5% of their body weight 7 - 12 months 4% of their body weight -const conditionsArray = [ - condition1, - condition2, - condition3, -] - -if (conditionsArray.indexOf(false) === -1) { - "do somthing" -} /*NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996 NOTE 2: This is a great time to check the tests to see what it expects, versus what is actually @@ -211,12 +201,33 @@ Use the game function below to do the following: - lose should return "you lose!" - tie should return "it's a tie" -RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors | Or there's a tie -*/ - -function game(user, computer){ - /*add your code here*/ +RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors | Or there's a tie*/ + +let cInput=Math.floor((Math.random()*3)); +console.log(cInput); +if (cInput===0){ + cInput= "scissors"; + console.log(cInput); +}else if (cInput===1){ + cInput= "paper"; + console.log(cInput); +}else{ + cInput= "rock"; + console.log(cInput); +} +function game(pInput,cInput){ + if (pInput==="rock" && cInput==="scissors" || pInput==="scissors" && cInput==="paper" || pInput==="paper" && cInput==="rock"){ + console.log("you win!"); + return; + }else if (cInput===pInput){ + console.log("it's a tie"); + return; + }else { + console.log("you lose!"); + return; + } } +game("scissors",cInput); @@ -231,9 +242,11 @@ Using the miles function below do the following: 3. Return the number of miles */ -function miles(/*add your code here*/){ - /*add your code here*/ +function miles(kilometers){ + console.log(kilometers*.621371); + return; } +miles(45); @@ -245,9 +258,11 @@ Using the feet function below do the following: 3. Return number of feet */ -function feet(/*add your code here*/){ - /*add your code here*/ +function feet(cm){ + console.log(cm*0.028084); + return; } +feet(10); @@ -265,9 +280,13 @@ Using the annoyingSong function below do the following: 4. Each time the annoyingSong is run from this loop, it should console.log the string that was returned. */ -function annoyingSong(/*add your code here*/){ - /*add your code here*/ +function annoyingSong(bottles){ + for (var i=bottles; i>0; i--){ + console.log(bottles+" bottles of soda on the wall, "+bottles+" bottles of soda, take one down pass it around, "+(bottles-1)+" of soda on the wall."); + var bottles=bottles-1; + } } +annoyingSong(15); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ From e002af61c0985a6f6faedaeda1fe4446e250cefc Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Fri, 23 Sep 2022 20:47:42 -0600 Subject: [PATCH 7/9] all tasks, including stretch completed --- index.js | 165 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 66 deletions(-) diff --git a/index.js b/index.js index 81be9681c..b3e4e408a 100644 --- a/index.js +++ b/index.js @@ -20,10 +20,10 @@ Do the following: HINT: no function required */ let votingAge=23; -if (votingAge<18){ - console.log("False"); +if (votingAge<=18){ + console.log('Task 1:a=', false); } else{ - console.log("True"); + console.log("Task 1:a=", true); } @@ -42,9 +42,9 @@ Do the following: let thingOne= 12; let thingTwo=3; if (thingOne===thingTwo){ - console.log("True"); + console.log('task 1b=', true); } else { - console.log("False") + console.log("task 1b=", false) } @@ -61,10 +61,8 @@ Do the following: HINT: look up the Number method */ -let numberC= "1999"; -numberC=== +1999; -console.log(numberC); - +const party= '1999'; +console.log('task 1c done the right way=', Number(party)); /* Task 1d - Multiply @@ -78,7 +76,7 @@ Do the following: function multiply(num1, num2){ return num1 * num2; } -console.log(multiply(12,3)); +console.log('task 1d=', multiply(12,3)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -94,7 +92,7 @@ Do the following: function dogYears(humanYear){ return humanYear*7; } -console.log(dogYears(33)); +console.log('task 2=', dogYears(Math.floor(Math.random()*100))); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -110,43 +108,6 @@ REMEMBER: This program should handle correctly adult AND puppy ages and weights HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters Feeding Requirements: - - -*/ -function hungryDog(weight, age){ - if (age<0.34){ - let percent=0.1; - let DFA= weight*percent; - console.log(weight, age, percent, DFA); - return; - } - else if (age <=.6 || age===1 && weight<=5){ - let percent=0.05; - let DFA= weight*percent; - console.log(weight, age, percent, DFA); - return; - } - else if (age <=.92 || age===1 && weight<=10){ - let percent=0.04; - let DFA= weight*percent; - console.log(weight, age, percent, DFA); - return; - } - else if (age===1 && weight<=15){ - let percent=0.03; - let DFA= weight*percent; - console.log(weight, age, percent, DFA); - return; - } - else { - let percent= 0.02; - let DFA= weight*percent; - console.log(weight, age, percent, DFA); - return; - } -} -hungryDog(7,1); -/* Adult Dogs 1 year and older up to 5 lbs - 5% of their body weight 6 - 10 lbs - 4% of their body weight @@ -177,7 +138,55 @@ NOTE 2: This is a great time to check the tests to see what it expects, versus w Notice the expected and received, expected is what the test is looking for, and received is what was actually returned from this function. You can also see it's passing in two values, the number 4 and the number 1. So, on this one test, the weight would be 4 pounds, and the age would be 1 years old. It's expecting your function to return a decimal number of 0.2 -*/ +*/ +function hungryDog(weight, age){ + if (age<0.33){ + let percent=0.1; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else if (age <=0.58 || age===1 && weight<=5){ + let percent=0.05; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else if (age <=1 || age===1 && weight<=10){ + let percent=0.04; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else if (age===1 && weight<=15){ + let percent=0.03; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else { + let percent= 0.02; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } +} +hungryDog(Math.ceil(Math.random()*10),(Math.random()*10)); @@ -207,23 +216,23 @@ let cInput=Math.floor((Math.random()*3)); console.log(cInput); if (cInput===0){ cInput= "scissors"; - console.log(cInput); + console.log('task 4= computer chooses', cInput); }else if (cInput===1){ cInput= "paper"; - console.log(cInput); + console.log('task 4= computer chooses', cInput); }else{ cInput= "rock"; - console.log(cInput); + console.log('task 4= computer chooses', cInput); } function game(pInput,cInput){ if (pInput==="rock" && cInput==="scissors" || pInput==="scissors" && cInput==="paper" || pInput==="paper" && cInput==="rock"){ - console.log("you win!"); + console.log("task 4= you win!"); return; }else if (cInput===pInput){ - console.log("it's a tie"); + console.log("task 4= its a tie"); return; }else { - console.log("you lose!"); + console.log("task 4= you lose!"); return; } } @@ -243,10 +252,10 @@ Using the miles function below do the following: */ function miles(kilometers){ - console.log(kilometers*.621371); + console.log('task 5a= '+ kilometers*.621371); return; } -miles(45); +miles(Math.ceil(Math.random()*10)); @@ -259,10 +268,10 @@ Using the feet function below do the following: */ function feet(cm){ - console.log(cm*0.028084); + console.log('task 5b= '+cm*0.028084); return; } -feet(10); +feet(Math.ceil(Math.random()*10)); @@ -286,7 +295,7 @@ function annoyingSong(bottles){ var bottles=bottles-1; } } -annoyingSong(15); +annoyingSong(Math.ceil(Math.random()*10)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -304,9 +313,26 @@ Using the grade function below do the following: below should return 'you got an F' */ -function grade(/*Your Code here */){ -/*Your Code here */ +function grade(gradeNumber){ + if (gradeNumber>89){ + console.log('task 7= ', gradeNumber, "You got an A!"); + return; + } else if (gradeNumber>79){ + console.log('task 7= ', gradeNumber, "You got a B!"); + return; + } else if (gradeNumber>69){ + console.log('task 7= ', gradeNumber, "You got a C!"); + return; + } else if (gradeNumber>59){ + console.log('task 7= ', gradeNumber, "You got a D!"); + return; + } else { + console.log('task 7= ', gradeNumber, "You got a F!"); + return; + } } + grade(Math.floor(Math.random()*100)); + @@ -322,16 +348,23 @@ HINT - you may need to study tomorrow's content on arrays HINT - try looking up the .includes() method */ - -function vowelCounter(/*add your code here*/) { - /*add your code here*/ +function vowelCounter(str){ + let getCount=0; + const vowels= ['a','e','i','o','u']; + for (let char of str){ + if (vowels.includes(char)){ + getCount++; + } + } + return getCount; } +console.log("There are",vowelCounter("its working"), "vowels in this sentence."); /*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/ function foo(){ - console.log('its working'); + console.log('final check= its working'); return 'bar'; } foo(); From b5307cdcd13580496984444121e425f4612c5a97 Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Fri, 23 Sep 2022 20:55:41 -0600 Subject: [PATCH 8/9] trying to fix the push --- index2.js | 382 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 index2.js diff --git a/index2.js b/index2.js new file mode 100644 index 000000000..b3e4e408a --- /dev/null +++ b/index2.js @@ -0,0 +1,382 @@ +/*🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️ Task 1: Warm-up! 🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️🏋️‍♂️*/ + +/*MAKE SURE TO RETURN ALL OF THE ANSWERS INSIDE OF A FUNCTION (tasks 1d through task 7), IF YOU DON'T, THE AUTOGRADER WILL NOT WORK*/ + +// task 1a, 1b, and 1c are not autograded + +/* +When doing these tasks, we recommend using console.log to test the output of your code to make sure it works correctly. +This will usually entail console logging the answer directly or console logging the invocation (call) of the function so when it +returns a value, that value will be logged to the console. An example of this would be: console.log(theFunction(value1,value2)) +*/ + +/* +Task 1a - Voting Age (not auto tested) + +Do the following: + 1. Create a variable called votingAge and assign it a number value + 2. Console log true if age is 18 or higher + + HINT: no function required +*/ +let votingAge=23; +if (votingAge<=18){ + console.log('Task 1:a=', false); +} else{ + console.log("Task 1:a=", true); +} + + + +/* +Task 1b - Values (not auto tested) + +Do the following: + 1. Declare two variables and assign them values (good names for these might be firstThing and secondThing) + 2. Use a conditional to check the value of the 1st variable versus the value assigned to the 2nd variable + 3. Change the value of the 1st variable if the conditional in step 2 is true + 4. Console log the value of the 1st variable + + HINT: no function required +*/ +let thingOne= 12; +let thingTwo=3; +if (thingOne===thingTwo){ + console.log('task 1b=', true); +} else { + console.log("task 1b=", false) +} + + + + +/* +Task 1c - Convert Strings to Numbers (not auto tested) + +Do the following: + 1. Declare a variable with the string type value of "1999" + 2. Convert the string value of "1999" to a integer value of 1999 + 3. Console log the result + + HINT: look up the Number method +*/ + +const party= '1999'; +console.log('task 1c done the right way=', Number(party)); + +/* +Task 1d - Multiply + +Do the following: + 1. Invoke the multiply function below and pass it two numbers + 2. Receive the parameters: a and b + 3. Multiply a and b and return the answer +*/ + +function multiply(num1, num2){ + return num1 * num2; +} +console.log('task 1d=', multiply(12,3)); + + +/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ + +//Age in Dog years +/* +Do the following: + 1. Invoke the dogYears function below and pass an age value to it + 2. Use the received value to calculate the age in dog years (1 human year is equal to 7 dog years) + 3. Return the newly calculated age +*/ + +function dogYears(humanYear){ + return humanYear*7; +} +console.log('task 2=', dogYears(Math.floor(Math.random()*100))); + + +/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ + +//Dog feeder - Depending on their weight and age, we need to know how many pounds of food to feed our dog each day! +/* +Use the hungryDog function and feeding requirements below to do the following: +1. Invoke the hungryDog function below and pass it a weight value in pounds, followed by an age value in years +2. 🌟 NOTE: if the dog is a puppy, the age will be a decimal (rounded to two places). For example: 3 months = .25 (3 divided by 12) +3. Do the proper calculations and return the number of pounds of raw food to feed the dog/puppy in a day + +REMEMBER: This program should handle correctly adult AND puppy ages and weights +HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters + +Feeding Requirements: +Adult Dogs 1 year and older + up to 5 lbs - 5% of their body weight + 6 - 10 lbs - 4% of their body weight + 11 - 15 lbs - 3% of their body weight + > 15lbs - 2% of their body weight + +Puppies less than 1 year + 2 - 4 months 10% of their body weight + 4 - 7 months 5% of their body weight + 7 - 12 months 4% of their body weight + +/*NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996 +NOTE 2: This is a great time to check the tests to see what it expects, versus what is actually + returned from your function. This is an example of the output to look for on each test point. + ● hungryDogFunction › Dog is 1 year and is 5lbs or less + + expect(received).toBe(expected) // Object.is equality + + Expected: 0.2 + Received: undefined + + 21 | describe('hungryDogFunction', ()=>{ + 22 | it('Dog is 1 year and is 5lbs or less', ()=>{ + > 23 | expect(functions.hungryDog(4, 1)).toBe(0.2); + | + ^ + 24 | }) + + Notice the expected and received, expected is what the test is looking for, and received is what was actually returned from this function. You can also see it's passing in two values, the number 4 and the number 1. + So, on this one test, the weight would be 4 pounds, and the age would be 1 years old. It's expecting your function to return a decimal number of 0.2 +*/ +function hungryDog(weight, age){ + if (age<0.33){ + let percent=0.1; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else if (age <=0.58 || age===1 && weight<=5){ + let percent=0.05; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else if (age <=1 || age===1 && weight<=10){ + let percent=0.04; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else if (age===1 && weight<=15){ + let percent=0.03; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } + else { + let percent= 0.02; + let DFA= weight*percent; + console.log ('task 3=', + "Weight=", weight, + "Age=", age, + "Percent of weight=", percent, + "Lbs of food per day=", DFA); + } +} +hungryDog(Math.ceil(Math.random()*10),(Math.random()*10)); + + + + + +/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ + +// Rock, Paper, Scissors - Let's play against the computer! +/* +Do the following: +1. Create a new variable that randomly generates the computer's choice, this must not be done inside the function +2. Use Math.random to determine the computer's choice (Math.random gives a random number between 0 and 1) +3. Make a conditional that changes the variable to "rock", "paper", or "scissors" based on it's random number + +Use the game function below to do the following: +1. Receive 2 parameters: a string with the user's choice of "rock", "paper", or "scissors" + and the computer's choice of "rock", "paper", or "scissors". + Note: make sure the strings are all lower case or it will not pass the test +2. Return whether the user won, lost, or tied based on these rules of the game described below - the strings returned need to match these strings below exactly. + - win should return "you win!" + - lose should return "you lose!" + - tie should return "it's a tie" + +RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors | Or there's a tie*/ + +let cInput=Math.floor((Math.random()*3)); +console.log(cInput); +if (cInput===0){ + cInput= "scissors"; + console.log('task 4= computer chooses', cInput); +}else if (cInput===1){ + cInput= "paper"; + console.log('task 4= computer chooses', cInput); +}else{ + cInput= "rock"; + console.log('task 4= computer chooses', cInput); +} +function game(pInput,cInput){ + if (pInput==="rock" && cInput==="scissors" || pInput==="scissors" && cInput==="paper" || pInput==="paper" && cInput==="rock"){ + console.log("task 4= you win!"); + return; + }else if (cInput===pInput){ + console.log("task 4= its a tie"); + return; + }else { + console.log("task 4= you lose!"); + return; + } +} +game("scissors",cInput); + + + +/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ + +//Metric Converter +//Task 5a - Kilometers to Miles +/* +Using the miles function below do the following: +1. Receive a number of kilometers +2. Convert the number of kiolmeters received to miles +3. Return the number of miles +*/ + +function miles(kilometers){ + console.log('task 5a= '+ kilometers*.621371); + return; +} +miles(Math.ceil(Math.random()*10)); + + + +//Task 5b - Centimeters to Feet +/* +Using the feet function below do the following: +1. Receive a number of cm +2. Convert the number of cm to feet +3. Return number of feet +*/ + +function feet(cm){ + console.log('task 5b= '+cm*0.028084); + return; +} +feet(Math.ceil(Math.random()*10)); + + + +/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ + +// Let's Sing 99 Bottles of Soda on the Wall! +/* +Using the annoyingSong function below do the following: +1. Receive a starting number +2. The annoying song function should return the following string exactly one time: + + "{number you gave as an argument} bottles of soda on the wall, {number you gave as an argument} bottles of soda, take one down pass it around {number you gave as an argument minus 1} bottles of soda on the wall" + +3. Outside of the function, Make a loop that invokes annoying song with a number that decreases until it gets to 1 bottle left. +4. Each time the annoyingSong is run from this loop, it should console.log the string that was returned. +*/ + +function annoyingSong(bottles){ + for (var i=bottles; i>0; i--){ + console.log(bottles+" bottles of soda on the wall, "+bottles+" bottles of soda, take one down pass it around, "+(bottles-1)+" of soda on the wall."); + var bottles=bottles-1; + } +} +annoyingSong(Math.ceil(Math.random()*10)); + + +/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ + +//Grade Calculator +/* +Using the grade function below do the following: +1. Receive a score out of 100 +2. Return the corresponding letter grade following this grade scale: + + 90-100 should return 'you got an A' + 80-89 should return 'you got a B' + 70-79 should return 'you got a C' + 60-69 should return 'you got a D' + below should return 'you got an F' +*/ + +function grade(gradeNumber){ + if (gradeNumber>89){ + console.log('task 7= ', gradeNumber, "You got an A!"); + return; + } else if (gradeNumber>79){ + console.log('task 7= ', gradeNumber, "You got a B!"); + return; + } else if (gradeNumber>69){ + console.log('task 7= ', gradeNumber, "You got a C!"); + return; + } else if (gradeNumber>59){ + console.log('task 7= ', gradeNumber, "You got a D!"); + return; + } else { + console.log('task 7= ', gradeNumber, "You got a F!"); + return; + } +} + grade(Math.floor(Math.random()*100)); + + + + +/*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/ + +//Vowel Counter - How many vowels are there? +/* +Using the vowelCounter function below do the following: +1. Receive a string as a parameter +2. Count and return the number of vowels within that string. It should handle both capitalized and uncapitalized vowels. + +HINT - you may need to study tomorrow's content on arrays +HINT - try looking up the .includes() method +*/ + +function vowelCounter(str){ + let getCount=0; + const vowels= ['a','e','i','o','u']; + for (let char of str){ + if (vowels.includes(char)){ + getCount++; + } + } + return getCount; +} +console.log("There are",vowelCounter("its working"), "vowels in this sentence."); + + + +/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/ +function foo(){ + console.log('final check= its working'); + return 'bar'; +} +foo(); +/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Don't touch the code after this line! 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/ +module.exports = { + foo, + multiply, + dogYears, + hungryDog, + game, + miles, + feet, + annoyingSong, + grade +} From fb8f6a66804d7d39329cf005c8b2918cbaba748b Mon Sep 17 00:00:00 2001 From: Beckon Roeckel Date: Wed, 28 Sep 2022 07:02:44 -0600 Subject: [PATCH 9/9] trying to fix problems --- index2.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/index2.js b/index2.js index b3e4e408a..aaf86ebe0 100644 --- a/index2.js +++ b/index2.js @@ -186,8 +186,7 @@ function hungryDog(weight, age){ "Lbs of food per day=", DFA); } } -hungryDog(Math.ceil(Math.random()*10),(Math.random()*10)); - +hungryDog(4,1); @@ -226,17 +225,17 @@ if (cInput===0){ } function game(pInput,cInput){ if (pInput==="rock" && cInput==="scissors" || pInput==="scissors" && cInput==="paper" || pInput==="paper" && cInput==="rock"){ - console.log("task 4= you win!"); + console.log("you win!"); return; }else if (cInput===pInput){ - console.log("task 4= its a tie"); + console.log("its a tie"); return; }else { - console.log("task 4= you lose!"); + console.log("you lose!"); return; } } -game("scissors",cInput); +game('rock','scissors'); @@ -271,7 +270,7 @@ function feet(cm){ console.log('task 5b= '+cm*0.028084); return; } -feet(Math.ceil(Math.random()*10)); +feet(30.48); @@ -315,23 +314,18 @@ Using the grade function below do the following: function grade(gradeNumber){ if (gradeNumber>89){ - console.log('task 7= ', gradeNumber, "You got an A!"); - return; + return 'you got an A'; } else if (gradeNumber>79){ - console.log('task 7= ', gradeNumber, "You got a B!"); - return; + return 'you got a B'; } else if (gradeNumber>69){ - console.log('task 7= ', gradeNumber, "You got a C!"); - return; + return 'you got a C'; } else if (gradeNumber>59){ - console.log('task 7= ', gradeNumber, "You got a D!"); - return; + return 'you got a D'; } else { - console.log('task 7= ', gradeNumber, "You got a F!"); - return; + return 'you got an F'; } } - grade(Math.floor(Math.random()*100)); + grade(20);