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



const votingAge = 23;
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)


var num = 15;
if(num < 18) {
console.log('You are a minor.');
} else if (num >= 18){
console.log('You are not a minor.');
}



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



Number("1999")


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




function multiply(param1, param2) {
return param1 * param2;
}
multiply(4,4)

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



Expand All @@ -36,6 +41,7 @@
//takes weight in pounds and age in years (note if the dog is a puppy the age will be a decimal) and returns the number of pounds of raw food to feed in a day.

//feeding requirements

// adult dogs at least 1 year
// up to 5 lbs - 5% of their body weight
// 6 - 10 lbs - 4% of their body weight
Expand All @@ -48,9 +54,31 @@
// 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, age){

if (age >=1 && weight <= 5){
return weight * 0.05
}
else if (age >=1 && (weight >=6 && weight <=10)){
return weight * 0.04
}
else if (age >=1 && (weight >=11 && weight <=15)){
return weight * 0.03
}
else if (age >=1 && weight > 15){
return weight * 0.02
}
else if (age >= 0.2 && age <= 0.39){
return weight * .1
}
else if (age >= .4 && age <= .69){
return weight * .05
}
else if (age >= 0.7 && age <= .12){
return weight * .04
}
}
dogFeeder(15,1);


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

var userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.33){
computerChoice = "rock";
}
else if (computerChoice <= 0.67 && computerChoice >= 0.34){
computerChoice = "paper";
}
else
{computerChoice = "scissors";
}

var compare = function(choice1, choice2);
if (choice1===choice2){
return("It's a tie!");
}
if (choice1==="rock"){
if(choice2==="scissors"){
return("Rock wins!");
}
else return("Paper wins!")
}
if(choice1==="paper"){
if(choice2==="rock"){
return("Paper wins!");
}
else return("Rock wins!")
}
if(choice1==="scissors"){
if(choice2==="rock"){
return("Rock wins!");
}
else return("Scissors win!");
}
compare(userChoice, computerChoice)



/************************************************************** Task 5 **************************************************************/
//Metric Converter
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles



//mi = km * 0.62137
function kilometers(param3){
return (param3 * 0.62137);
}
kilometers(13)


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


//cm = ft/0.032808
function feet(param4){
return (param4/0.032808);
}
feet(14)



/************************************************************** 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(bottles){
var bottles;
// var bottlesLeft;
for(i=99, i>=1, i--){
console.log(bottles + " bottles of soda on the wall, " + bottles " bottles of soda, " + " take one down pass it around " + bottles + " bottles of soda on the wall.");
}
}
annoyingSong(99);


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

function gradeCalculator(number){
if(number >= 90){
return ("You got an A!");
}
else if(number >=80 && number <=89){
return ("You got a B!");
}
else if(number >=70 && number <=79){
return ("You got a C.");
}
else if(number >=60 && number <=69){
return ("You got a D.");
}
else if(number <60){
return ("Sorry, you failed.");
}
}

gradeCalculator(100)



Expand Down