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
126 changes: 101 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)
let votingAge = 20;


if (votingAge > 18) {
console.log('True')
} else {
console.log('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 myFavoriteGame = 'Minecraft';
let myActualFavGame = 'Call of Duty';




if (myFavoriteGame = 'Minecraft'){
myFavoriteGame = myActualFavGame;
console.log(myFavoriteGame);
}

//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method
const conversion = "1999";



console.log(parseInt(conversion));


//Task d: Write a function to multiply a*b
const a = 20;
const b = 3;




function solution (num1, num2) {
return num1 * num2;
}
console.log(solution(a, b));

/************************************************************** Task 2 **************************************************************/
//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
let myAge = 21;

function myAgeInDogYears (vr) {
return vr * 7;
}



console.log(myAgeInDogYears(myAge))

/************************************************************** Task 3 **************************************************************/
//Dog feeder
Expand All @@ -48,9 +62,24 @@
// 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 dogFeederAdults(weight, age){
if (weight <= 5 && age >= 1){
return weight * 0.05;
}else if (weight >= 6 && weight <=10 && age >= 1) {
return weight * 0.04;
}else if (weight >= 11 && weight <=15 && age >= 1) {
return weight * 0.03;
}else if (weight >= 16 && age >= 1){
return weight * 0.02;
}else if (age >= .166 && age < .333){
return weight * 0.1;
}else if (age >.333 && age < .583){
return weight * .05;
}else (age > .583 && age < 1)
return weight * .04;
}

console.log(dogFeederAdults(15, 1));


/************************************************************** Task 4 **************************************************************/
Expand All @@ -60,30 +89,67 @@
// 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




function RPS(choiceOf) {

let brain = Math.floor(Math.random() * Math.floor(3));

if (brain === 0 && choiceOf === 'rock') {
return(`It's a tie, you both chose ${choiceOf}`);
} else if (brain === 0 && choiceOf === 'sissor'){
return(`You lose you chose ${choiceOf} but the computer destroyed you with ROCK!`)
} else if(brain === 0 && choiceOf === 'paper') {
return(`Good job! You beat the computer with ${choiceOf}`)


} else if (brain === 1 && choiceOf === 'paper'){
return(`It's a tie, you both chose ${choiceOf}`)
} else if(brain === 1 && choiceOf === 'sissor') {
return(`Good job! You beat the computer with ${choiceOf}`)
}else if (brain === 1 && choiceOf === 'rock'){
return(`You lose you chose ${choiceOf} but the computer destroyed you!`)


} else if(brain === 2 && choiceOf === 'sissor') {
return(`It's a tie, you both chose ${choiceOf}`)
}else if (brain === 2 && choiceOf === 'rock'){
return(`You lose you chose ${choiceOf} but the computer destroyed you!`)
} else if(brain === 2 && choiceOf === 'paper') {
return(`Good job! You beat the computer with ${choiceOf}`)
}
}
console.log(RPS('paper'));


/************************************************************** Task 5 **************************************************************/
//Metric Converter
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles
function kmToM (kilo){
return kilo * 0.6214;
}



console.log(kmToM(20));


//b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters


function fTC (length){
return length * 30.48
}

console.log(fTC(12))


/************************************************************** 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 (bottle){
for (let i = bottle; i > 0; i--){
return `${bottle} bottles of soda on the wall, ${bottle} bottles of soda, take one down pass it around ${bottle - 1} bottles of soda on the wall`;
}
}

console.log(annoyingSong(19));


/************************************************************** Task 7 **************************************************************/
Expand All @@ -95,9 +161,20 @@
//60s should be D
//and anything below 60 should be F



function grades (mark){
if (mark >= 90){
return 'A grade';
} else if (mark >= 80 && mark <= 89){
return 'B grade';
} else if (mark >= 70 && mark <= 79){
return 'C grade';
} else if (mark >=60 && mark <= 69){
return 'D grade';
} else (mark <= 59)
return 'F grade';
}

console.log(grades(88));

/************************************************************** Stretch **************************************************************/
//Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.
Expand All @@ -115,4 +192,3 @@