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
132 changes: 118 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +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);
}



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

//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 i = 1;
i++;
if(i <= 7) {
console.log(i);
}



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


let x = ('1999');
console.log(Number(x));



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


function multiply (num1,num2){
return (num1 * num2);
}
console.log (multiply(7,7));



/************************************************************** 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(humanAge) {
return(humanAge * 7);
}

console.log(dogYears(5));



Expand All @@ -50,6 +66,25 @@
// 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 (dogWeight, dogAge) {
if (dogAge >= 1 && dogWeight <= 5) {
return(.05 * dogWeight);
} else if (dogAge >= 1 && (dogWeight >= 6 && dogWeight <= 10)) {
return(.04 * dogWeight);
} else if (dogAge >= 1 && (dogWeight >= 11 && dogWeight <= 15)) {
return(.03 * dogWeight);
} else if (dogAge >= 1 && dogWeight > 15) {
return(.02 * dogWeight);
} else if (dogAge >= .2 && dogAge < .4) {
return(.1 * dogWeight);
} else if (dogAge >= .4 && dogAge < .7) {
return(.05 * dogWeight);
} else if (dogAge >= .7 && dogAge < 1) {
return(.04 * dogWeight);
}
}

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



Expand All @@ -59,20 +94,50 @@
// 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 generateComputerHand(){
let hands = {0:"rock", 1:"paper", 2:"scissors"};
let randomIndex = Math.floor(Math.random() * 3); //a random index is either 0, 1 or 2
let computerHand = hands[randomIndex]; //this will produce either rock, paper or scissors
return computerHand
}

function winner(me, computerHand) {
if (me === computerHand) {
return "Tied!";
} else if (me === "rock" && computerHand === "scissors") {
return "You won!";
} else if (me === "paper" && computerHand === "rock") {
return "You won!";
} else if (me === "scissors" && computerHand === "paper") {
return "You won!";
} else {
return "You lost!";
}
}

let computer = generateComputerHand();
console.log(winner("scissors", computer))

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

console.log(kilometerConverter(7))




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

function centimeterConverter(feet) {
let centimeters = (feet * 30.48);
return centimeters
}

console.log(centimeterConverter(2))



Expand All @@ -81,9 +146,20 @@
// 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) {
while(num >= 0) {
let newNum = num-1
if (num > 1) {
console.log(num + " bottles of soda on the wall, " + num + " bottles of soda, take one down, pass it around, " + newNum + " bottles of soda on the wall.");
} else if (num === 1) {
console.log(num + " bottle of soda on the wall, " + num + " bottle of soda, take one down, pass it around, no bottles of soda on the wall.");
} else {
console.log("You're out of sodas!") }
num--
}
}

annoyingSong(99)


/************************************************************** Task 7 **************************************************************/
Expand All @@ -94,8 +170,21 @@
//70s should be Cs
//60s should be D
//and anything below 60 should be F


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

console.log(gradeCalculator(90))



Expand All @@ -104,7 +193,22 @@
// Hint - you may need to study tomorrow's traning kit on arrays
// try looking up the .includes() method


function vowel_count(str1)
{
var vowel_list = 'aeiouAEIOU';
var vcount = 0;

for(var x = 0; x < str1.length ; x++)
{
if (vowel_list.indexOf(str1[x]) !== -1)
{
vcount += 1;
}

}
return vcount;
}
console.log(vowel_count("The quick brown fox"));



Expand Down