Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 103 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Do the following:




/*
Task 1b - Values

Expand Down Expand Up @@ -58,9 +59,9 @@ Do the following:
3. Multiply a and b and return the answer
*/

function multiply(/*add your code here*/){
/*add your code here*/
}
function multiply(a, b){
return a * b;
}



Expand All @@ -74,8 +75,8 @@ Do the following:
3. Return the newly calculated age
*/

function dogYears(/*add your code here*/){
/*add your code here*/
function dogYears(age){
return age * 7;
}


Expand Down Expand Up @@ -107,9 +108,35 @@ Use the hungryDog function and feeding requirements below to do the following:
NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996
*/

function hungryDog(/*add your code here*/){
/*add your code here*/
function hungryDog(weight, age){
if (age < 1){
if (age < .333){
return weight * 0.1;
}
else if (age > .333 && age < 0.583){
return weight * 0.05;
}
else {
return weight * 0.04;
}
}
else {
if (weight < 5){
return weight * 0.05;
}
else if (weight > 5 && weight < 10){
return weight * 0.04;
}
else if (weight > 10 && weight <= 15){
return weight * 0.03;
}
else {
return weight * 0.02;
}
}
}

hungryDog();



Expand All @@ -132,9 +159,45 @@ Use the game function below to do the following:
HINT: While you can complete this with only conditionals based on strings, it may help to equate choice to a number when using Math.random()
*/


function game(user, computer){
/*add your code here*/
if (user === computer){
return "it's a tie";
}
else if (user === "rock" && computer === "paper" || user === "paper" && computer === "scissors" || user === "scissors" && computer === "rock") {
return "you lose!";
}
else {
return "you win!";
}
}

function userChoice() {
const x = Math.random();
if (x <= 0.33){
return "paper";
}
else if (x < 0.66){
return "rock";
}
else if (x <= 1){
return "scissors";
}
}
function computerChoice() {
const x = Math.random();
if (x <= 0.33){
return "paper";
}
else if (x < 0.66){
return "rock";
}
else if (x <= 1){
return "scissors";
}
}
console.log(game(userChoice(), computerChoice()));




Expand All @@ -149,9 +212,9 @@ 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(km){
return km * 0.621371;
}



Expand All @@ -163,9 +226,9 @@ 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){
return cm / 30.48;
}



Expand All @@ -179,9 +242,17 @@ Using the annoyingSong function below do the following:
"(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(/*add your code here*/){
/*add your code here*/
function annoyingSong(number){
// for (i = number; i > 0; i--){
// return number + " bottles of soda on the wall, " + number + " bottles of soda, take one down pass it around " + (number - 1) + " bottles of soda on the wall";
// }
let string = "";
while (number > 0){
string += number + " bottles of soda on the wall, " + number + " bottles of soda, take one down pass it around " + (number - 1) + " bottles of soda on the wall";
number--;
}
return string;
}


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/
Expand All @@ -199,9 +270,23 @@ Using the grade function below do the following:
below 60 = F
*/

function grade(/*add your code here*/){
/*add your code here*/
function grade(score){
if (score > 90){
return "you got a A";
}
else if (score < 90 && score >= 80){
return "you got a B";
}
else if (score < 80 && score >= 70){
return "you got a C";
}
else if (score < 70 && score >= 60){
return "you got a D";
}
else {
return "you got an F";
}
}



Expand Down