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

let votingAge = 19;

console.log("votingAge", votingAge > 18)



//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 variable = "variable";

let variable2 = "variable 2"

variable = variable2;

console.log('variable', variable)


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

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

console.log('number("1999)"', Number("1999"))



//Task d: Write a function to multiply a*b

function multiply(a, b) {
return a * b;
}

console.log('multiply ab', multiply(1, 2))



/************************************************************** 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

function dogYear(age) {
return age * 7
}


console.log('dogYear', dogYear(30))


/************************************************************** Task 3 **************************************************************/
Expand All @@ -48,56 +63,172 @@
// 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 dogFood(weight, age) {
if (age < 1) {
if (age > 0.1667 && age <= 0.3333) {
return weight * 0.1;
} else if (age > 0.3333 && age <= 0.5833) {
return weight * 0.05;
} else if (age > 0.5833 && age < 1) {
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 if (weight > 15) {
return weight * 0.02;
}
}
}

console.log('dogFood', dogFood(15, 1))


/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
// Your function should take a string (either rock paper or sissors)
// Rock, Paper, Scissors
// Your function should take a string (either rock paper or scissors)
// it should return you won or you lost based on the rules of the game (you may need to look up the rules if you have not played before)
// 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(user) {

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

let compString = '';

let winner = '';

switch (compChoice) {
case 0:
compString = 'rock';
break;
case 1:
compString = 'paper';
break;
case 2:
compString = 'scissors';
break;
}

console.log('computer choice', compString);

switch (user) {
case 'rock':
switch (compString) {
case 'rock':
winner = 'Tie';
break;
case 'scissors':
winner = 'Win!';
break;
case 'paper':
winner = 'Lost'
};
break;
case 'paper':
switch (compString) {
case 'rock':
winner = "Win!";
break;
case 'scissors':
winner = "Lost";
break;
case 'paper':
winner = "Tie";
};
break;
case 'scissors':
switch (compString) {
case 'rock':
winner = "Lost";
break;
case 'scissors':
winner = "Tie";
break;
case 'paper':
winner = "Win!";
break;
}
break;
default:
winner = "Not enough data"
}

return winner;

}

console.log('rps', rps('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 kiloToMile(km) {
return km * 0.621371;
}



console.log('kiloToMile', kiloToMile(5));

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


function feetToCM(ft) {
return ft * 30.48;
}

console.log('feetToCM', feetToCM(5))


/************************************************************** 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(startNum) {


for (let i = startNum; i > 0; i--) {

console.log(i + " bottles of soda on the wall, " + i + ' bottles of soda, take one down, pass it around ' + (i - 1) + " bottles of soda on the wall")
}
}

annoyingSong(3);



/************************************************************** Task 7 **************************************************************/
//Grade Calculator
//write a javaScript program that takes a mark out of 100 and returns a corisponding letter grade
//write a javaScript program that takes a mark out of 100 and returns a corresponding letter grade
//90s should be A
//80s should be B
//70s should be Cs
//60s should be D
//and anything below 60 should be F




function gradeCalc(grade) {
if (grade >= 90) {
return "A";
} else if (grade < 90 && grade >= 80) {
return "B";
} else if (grade < 80 && grade >= 70) {
return "C";
} else if (grade < 70 && grade >= 60) {
return "D";
} else {
return "F"
}
}

console.log('gradeCalc', gradeCalc(40))

/************************************************************** Stretch **************************************************************/
//Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.
Expand Down