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
11 changes: 7 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<script src="index.js"></script>
<script src="index.js"></script>
</body>

</html>
185 changes: 166 additions & 19 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 = 18;


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 time = 22;



if (time >= 6 && time < 12) {
time = 'morning';
} else if (time >= 12 && time < 18) {
time = 'afternoon';
} else {
time = 'evening';
}

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

let num = '1999';


parseInt(num);


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


function mutiply(a, b) {
return 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



function dogYears(humanYear) {
return humanYear * 7;
}


/************************************************************** Task 3 **************************************************************/
Expand All @@ -48,10 +63,32 @@
// 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 dogFeeder(weight, years) {

while (years >= 1) {
if (weight <= 5) {
return weight * 0.05;
} else if (weight >= 6 && weight <= 10) {
return weight * 0.04;
} else if (weight >= 11 && weight <= 15) {
return weight * 0.03;
} else {
return weight * 0.02;
}
}

if (years >= 0.16 && years <= 0.33) {
return weight * 0.1;
} else if (years > 0.33 && years <= 0.58) {
return weight * 0.05;
} else if (years > 0.58 && years < 1) {
return weight * 0.04;
}
}

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

/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
Expand All @@ -60,31 +97,78 @@
// 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 rockPapersSissors(shoot) {

// let phrase = `It's a draw!`;

// let compChoice = Math.random();

// if (compChoice <= 0.33) {
// compChoice = 'rock';
// } else if (compChoice > 0.33 && compChoice <= 0.66) {
// compChoice = 'scissors';
// } else {
// compChoice = 'paper';
// }

// if (compChoice === 'rock') {
// if (shoot === 'paper') {
// phrase = 'You win';
// } else if (shoot === 'scissors') {
// phrase = 'You lose';
// }
// }
// if (compChoice === 'scissors') {
// if (shoot === 'rock') {
// phrase = 'You win!';
// } else if (shoot === 'paper') {
// phrase = 'You lose!';
// }
// }
// if (compChoice === 'paper') {
// if (shoot === 'rock') {
// phrase = 'You lose!';
// } else if (shoot === 'scissors') {
// phrase = 'You win!';
// }
// }
// return phrase;
// }

// rockPapersSissors('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 convertKilometers(num) {
return num * 0.62;
}




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


function convertFeet(num) {
return num * 30.48;
}



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

annoyingSong(2);

/************************************************************** Task 7 **************************************************************/
//Grade Calculator
Expand All @@ -94,25 +178,88 @@
//70s should be Cs
//60s should be D
//and anything below 60 should be F




function gradeCalculator(score) {
let grade = 'F';

if (score >= 90) {
grade = 'A';
} else if (score >= 80 && score < 90) {
grade = 'B';
} else if (score >= 70 && score < 80) {
grade = 'C';
} else if (score >= 60 && score < 70) {
grade = 'D';
}
return grade;
}

console.log(gradeCalculator(59));

/************************************************************** Stretch **************************************************************/
//Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.
// Hint - you may need to study tomorrow's traning kit on arrays
// try looking up the .includes() method

const vowels = 'aeiou';

function countVowels(str) {
let numVowels = 0;
let lowerStr = str.toLowerCase();

for (let i = 0; i < str.length; i++) {
if (vowels.includes(lowerStr[i])) {
numVowels++;
}
}
return numVowels;
}


/************************************************************** Stretch **************************************************************/
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object





function rockPapersSissors() {
let shoot = prompt('Rock, paper, or scissors?');

let phrase = `It's a draw`;

let compChoice = Math.random();

if (compChoice <= 0.33) {
compChoice = 'rock';
} else if (compChoice > 0.33 && compChoice <= 0.66) {
compChoice = 'scissors';
} else {
compChoice = 'paper';
}

// if (shoot !== 'rock' || shoot !== 'paper' || shoot !== 'scissors') {
// phrase = 'Pick rock, paper, or scissors';
// }

if (compChoice === 'rock') {
if (shoot === 'paper') {
phrase = 'You win';
} else if (shoot === 'scissors') {
phrase = 'You lose';
}
}
if (compChoice === 'scissors') {
if (shoot === 'rock') {
phrase = 'You win!';
} else if (shoot === 'paper') {
phrase = 'You lose!';
}
}
if (compChoice === 'paper') {
if (shoot === 'rock') {
phrase = 'You lose!';
} else if (shoot === 'scissors') {
phrase = 'You win!';
}
}
return phrase;
}