Skip to content
Open
Show file tree
Hide file tree
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
130 changes: 106 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Do the following:
HINT: no function required
*/

/* const votingAge = 18;
if (votingAge >= 18) {
console.log('true');
} */


/*
Expand All @@ -31,6 +35,13 @@ Do the following:
HINT: no function required
*/

/* let var1 = 1;
let var2 = 2;
if (var2 >= 2) {
var1 = 2;
}
console.log var1; */




Expand All @@ -46,6 +57,10 @@ Do the following:
HINT: look up the Number method
*/

/* const string = '1999';
console.log(Number(string)); */





Expand All @@ -58,9 +73,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 +89,9 @@ Do the following:
3. Return the newly calculated age
*/

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


Expand All @@ -86,6 +102,7 @@ function dogYears(/*add your code here*/){
/*
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

2. Also, pass to hungryDog an age value in years (note: if the dog is a puppy, the age will be a decimal. For example: three months = 3/12 or .25)
3. Do the proper calculations and return the number of pounds of raw food to feed the dog/puppy in a day

Expand All @@ -107,18 +124,40 @@ 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(weightLbs,ageYears) {
if (ageYears >= 1) {
if (weightLbs <= 5) {
return weightLbs * .05;
} else if (weightLbs >= 6 && weightLbs <= 10) {
return weightLbs * .04;
} else if (weightLbs >= 11 && weightLbs <= 15) {
return weightLbs * .03;
} else {
return weightLbs * .02;
}
}

else {
if (ageYears >= (2/12) && ageYears < (4/12)) {
return weightLbs * .10;
} else if (ageYears >= (4/12) && ageYears < (7/12)) {
return weightLbs * .05;
} else if (ageYears >= (7/12) && ageYears < 1) {
return weightLbs * .04;
} else {
console.log("Your pet can't eat this kind of food yet!");
}
}
}
console.log(hungryDog(15,1));
console.log(hungryDog(5,0));


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

// Rock, Paper, Scissors - Let's play against the computer!
/*
Create a global variable that randomly generates the computer's choice
Use Math.random to determine the computers choice (Math.random gives a random number between 0 and 1)
Use Math.random to determine the computers choice (Math.random gives a random number between 0 and 1) <-- BREAK INTO 3RDS

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()

Expand All @@ -134,11 +173,36 @@ Use the game function below to do the following:
HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters
*/

let computer = Math.random();

// computer's roll
if (computer <= (1/3)){
computer = 'rock';
} else if (computer <= (2/3)) {
computer = 'paper';
} else {
computer = 'scissors';
}

function game(user, computer){
/*add your code here*/
// who won?
if (user === computer) { // eliminate tied outcomes first
return "it's a tie";
} else if (user === 'rock') { // rock outcomes (2 outcomes now that tie is eliminated)
if (computer === 'scissors') {
return "you win!";
} else return "you lose!";
} else if (user === 'paper') {
if (computer === 'rock') {
return "you win!";
} else return "you lose!";
} else if (user === 'scissors') {
if (computer === 'paper') {
return "you win!";
} else return "you lose!";
}
}


console.log(game("paper",computer));

/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -147,13 +211,14 @@ function game(user, computer){
/*
Using the miles function below do the following:
1. Receive a number of kilometers
2. Convert the number of kiolmeters received to miles
2. Convert the number of kilometers received to miles
3. Return the number of miles
*/

function miles(/*add your code here*/){
/*add your code here*/
function miles(km){
return (km * 0.621371);
}
console.log(miles(20));



Expand All @@ -165,9 +230,10 @@ 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);
}
console.log(feet(50));



Expand All @@ -181,8 +247,8 @@ 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){
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`;
}


Expand All @@ -201,9 +267,17 @@ 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(score){
if (score >= 90) {
return "you got an A";
} else if (score >= 80) {
return "you got a B";
} else if (score >= 70) {
return "you got a C";
} else if (score >= 60) {
return "you got a D";
} else return "you got an F";
}



Expand All @@ -220,9 +294,17 @@ Using the vowelCounter function below do the following:
*/


function vowelCounter(/*add your code here*/) {
/*add your code here*/
function vowelCounter(string) {
let vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u', 'Y', 'y'];
let vowelCount = 0;
for (let i = 0; i < string.length; i++) {
if (vowels.includes(string[i])) {
vowelCount++;
}
}
return vowelCount;
}
console.log(vowelCounter('Animal'));



Expand Down
Loading