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
148 changes: 123 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Do the following:

HINT: no function required
*/
var votingAge = 18;
if (votingAge >= 18){
return true;
}



Expand All @@ -30,7 +34,12 @@ Do the following:

HINT: no function required
*/

var a = 25;
let b = 30;
if (b > a){
a = 20;
return a;
}



Expand All @@ -45,7 +54,12 @@ Do the following:

HINT: look up the Number method
*/

var year = "1999";
function number(){
year = Number(year);
return year;
}
number();



Expand All @@ -58,9 +72,11 @@ Do the following:
3. Multiply a and b and return the answer
*/

function multiply(/*add your code here*/){
/*add your code here*/
}
function multiply(num1, num2){
answer = num1 * num2;
return answer;
}




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

function dogYears(/*add your code here*/){
/*add your code here*/
function dogYears(humanYears){
dog = humanYears * 7;
return dog;
}


Expand Down Expand Up @@ -107,8 +124,27 @@ 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(dogWeight, dogAge){
if (dogAge >= 1){
if (dogWeight <= 5){
dogFood = dogWeight * .05;
} else if (dogWeight >= 6 && dogWeight <= 10){
dogFood = dogWeight * .04;
} else if (dogWeight >= 11 && dogWeight <= 15){
dogFood = dogWeight * .03;
} else if (dogWeight > 15){
dogFood = dogWeight * .02;
}
} else if (dogAge < 1){
if (dogAge >= .16 && dogAge <= .33){
dogFood = dogWeight * .1;
} else if (dogAge >= .34 && dogAge <= .58){
dogFood = dogWeight * .05;
} else if (dogAge >= .59 && dogAge <= .99){
dogFood = dogWeight * .04;
}
}
return dogFood;
}


Expand All @@ -127,8 +163,40 @@ 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(/*add your code here*/){
/*add your code here*/
function game(userChoice){
var computerChoice = Math.random();
if (computerChoice < .34){
computerChoice = "rock";
} else if (computerChoice >=.34 && computerChoice < .67){
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
if (userChoice === "rock"){
if (userChoice === computerChoice){
return "tie!";
} else if (computerChoice === "paper"){
return "you lost";
} else {
return "you win";
}
} else if (userChoice === "paper"){
if (userChoice === computerChoice){
return "tie!";
} else if (computerChoice === "scissors"){
return "you lost";
} else {
return "you win";
}
} else if (userChoice === "scissors"){
if (userChoice === computerChoice){
return "tie!";
} else if (computerChoice === "rock"){
return "you lost";
} else {
return "you win";
}
}
}


Expand All @@ -144,8 +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(kilometers){
mile = kilometers * .621371;
return mile;
}


Expand All @@ -158,8 +227,9 @@ Using the feet function below do the following:
3. Return number of centimeters
*/

function feet(/*add your code here*/){
/*add your code here*/
function feet(feetAmount){
centimeters = feetAmount * 30.48;
return centimeters;
}


Expand All @@ -174,9 +244,14 @@ 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(numberReceived){
for (let i=numberReceived; i>0; i--){
if (i > 0){
console.log(numberReceived + " bottles of soda on the wall, " + numberReceived + " bottles of soda, take one down pass it around " + (numberReceived - 1) + " bottles of soda on the wall");
}
numberReceived = i - 1;
}
}


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/
Expand All @@ -194,9 +269,26 @@ 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 && score <= 100){
letterGrade = "A";
return letterGrade;
} else if (score >= 80 && score <= 89){
letterGrade = "B";
return letterGrade;
} else if (score >= 70 && score <= 79){
letterGrade = "C";
return letterGrade;
} else if (score >= 60 && score <= 69){
letterGrade = "D";
return letterGrade;
} else {
letterGrade = "F";
return letterGrade;
}
}





Expand All @@ -213,12 +305,18 @@ Using the vowelCounter function below do the following:
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*/
const vowels = ["a", "e", "i", "o", "u"]
function vowelCounter(word) {
let count = 0;
for (let letter of word.toLowerCase()) {
if (vowels.includes(letter)){
count++;
}
}
return count;

}

vowelCounter("stop");


/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/
Expand Down