diff --git a/index.js b/index.js index 73f240372..d808d5ad7 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,32 @@ /************************************************************** Task 1: Warm-up! **************************************************************/ //Task a: declare a variable called votingAge, console log true if age > 18 (no function required) - - - +var votingAge = 21 +if (votingAge > 18) { + console.log ("true") + } else { + return "false"; + } //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 first = 1 +let second = 2 +if (first < second) { + return (first + 1) +} //Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method - +let string = "1999"; +Number (string); //Task d: Write a function to multiply a*b - +function dogAge(myage) { + return(myAge)*7; +} @@ -27,9 +35,9 @@ //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 dogAge (myAge) { + return (myAge)*7; +} /************************************************************** Task 3 **************************************************************/ //Dog feeder @@ -48,10 +56,25 @@ // 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 dogFeedwr (weight,age) { + if (weight<=5) { + console.log ("5% of their body weight"); + } else if (weight<=10) { + console.log ("4% of their body weight"); + } else if (weight<=15) { + console.log ("3% of their body weight"); + } else if (weight>15) { + console.log ("2% of their body weight"); + //AGE// + } else if (age<4) { + console.log ("10% of their body weight"); + } else if (age<7) { + console.log ("10% of their body weight"); + } else if(age<12) { + console.log ("4% of their body weight"); + } + } /************************************************************** Task 4 **************************************************************/ // Rock, Paper, Sissors @@ -60,28 +83,29 @@ // 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 - + let random = math.random(); + if (random<=0.33) { + computerChoice = "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 (kilometers) { + return (kilometers) * 0.62; +} //b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters - - - - + function feetToCentimeter (feet) { + return (feet) * 30.48 + } /************************************************************** Task 6 **************************************************************/ // 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 () @@ -94,10 +118,18 @@ //70s should be Cs //60s should be D //and anything below 60 should be F - + let grade = 90 + if (grade >= 90 && grade <= 100); { + return ("A") + } else if (grade >= 80 && grade <= 89); { + return ("B") + } else if (grade >= 70 && grade <= 79); { + return ("C") + } else if (grade >= 60 && grade <= 69); { + return ("D") + } else if (grade >= 59 && grade <= 0); { + } - - /************************************************************** Stretch **************************************************************/ //Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.