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
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js"
}
]
}
142 changes: 131 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)

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

var variable1 = 20
var variable2 = 5

if(variable1 = 20){
console.log(variable1 + variable2)
}



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


var value1 = "23"

parseInt(value1);

console.log(value1)


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

const a = 2
const b = 4

function multiply(a, b) {

const product = a * b;

return product

}
console.log(multiply(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

const myAge = 20;
const dogAge = 7;

function dogYears (myAge, dogAge) {

const newAge = myAge * dogAge;

return newAge;

}

console.log(dogYears(myAge, dogAge));


/************************************************************** Task 3 **************************************************************/
Expand All @@ -48,9 +80,37 @@
// 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 (age, weight) {

if(age >= 1 && weight <= 5) {
return weight * .05;
}
else if (age >= 1){
if (weight >= 6 && weight <= 10) {
return weight * .04;
}
else if (age >= 1) {
if (weight >= 11 && weight <= 15) {
return weight * .03;
}
else if (age >= 1 && weight >= 15) {
return weight * .02;
}
}
}

if (age >= .2 && age < .4) {
return weight * .1;
} else if (age >= .4 && age < .7) {
return weight * .05;
} else if (age >= .7 && age < 1) {
return weight * .04;
}
}

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


/************************************************************** Task 4 **************************************************************/
Expand All @@ -60,31 +120,79 @@
// 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 computerChoice1() {

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

if (computerSelection === 0) {
return "rock";
} else if (computerSelection === 1) {
return "paper";
} else if (computerSelection === 2) {
return "scissors";
}

}

function game (userChoice) {
const computerChoice = computerChoice1();
// console.log(computerChoice);
// console.log(userChoice);
if(userChoice === computerChoice) {
console.log ("Tie");
} else if (userChoice === "rock" && computerChoice === "paper") {
console.log ("loss! paper beats rock");
} else if (userChoice === "rock" && computerChoice === "scissors") {
console.log ("win! rock beats scissors");
} else if (userChoice === "paper" && computerChoice === "rock") {
console.log ("win! paper beats rock");
} else if (userChoice === "paper" && computerChoice === "scissors") {
console.log ("loss! scissors beat paper");
} else if (userChoice === "scissors" && computerChoice === "rock") {
console.log ("loss! rock beats scissors");
} else if (userChoice === "scissors" && computerChoice === "paper") {
console.log ("win! scissors beat paper");
}
}

game("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 kiloConverter (kilo) {
console.log (kilo * 0.621372);
}


kiloConverter(5);


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

function feetConverter (feet) {
console.log (feet * 30.48);
}



feetConverter(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 (startingNumber) {
var i = 0;
var bottles = startingNumber;

while (i != startingNumber) {
console.log(bottles, "bottles of soda on the wall");
i++;
bottles--;
}
}


annoyingSong(99);

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




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

gradeCalculator(76);

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