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"
}
]
}
102 changes: 82 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)


var votingAge = 25;
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 fruit1 = "Apple";
let isTasty = "Yum";

if(isTasty === "Yum"){
fruit1 = "Delicious";
}else {
fruit1 = "Gross";
}

console.log(fruit1);



//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
let number = "1999";
Number(number);
console.log(Number(number));


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


function multiply(a, b) {
let total = a * b;
return total
}
console.log(multiply(2, 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 (myAge){
const x = myAge * 7;
return x
}
console.log(dogYears(25));

/************************************************************** Task 3 **************************************************************/
//Dog feeder
Expand All @@ -48,7 +66,29 @@
// 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 (wgt, age) {
if(age >= 1 && wgt <= 5) {
return wgt * 0.05
} if (age >= 1 && wgt >= 6 || wgt <= 10) {
return wgt * 0.04
} if (age >= 1 && wgt >= 11 || wgt <= 15 ){
return wgt * 0.03
} if (age >= 1 && wgt > 15){
return wgt * 0.02
}
}
console.log(dogFeeder(15, 1));

function puppyFeeder (wgt, age) {
if(age > 0.08 || age <= 0.3){
return wgt * 0.1
} else if (age >= 0.3 || age <= 0.58){
return wgt * 0.05
} else if (age >= 0.58 || age <= 0.99){
return wgt * 0.04
}
}
console.log(puppyFeeder(15, 1));



Expand All @@ -59,21 +99,48 @@
// 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 handGame(compChoice) {
const r = "rock"
const p = "paper"
const s = "scissors"
var compChoice = Math.random()

if (compChoice == 1 && r == 1){
return "won"
} else if (compChoice < 1) {
return "lost"
} else if (compChoice == .5 && p == .5) {
return "won"
} else if (compChoice < .5) {
return "lost"
} else if (compChoice == .1 && s == .1){
return "won"
} else if (compChoice > .1) {
return "lost"
}
}
console.log(handGame());


/************************************************************** Task 5 **************************************************************/
//Metric Converter
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles
function metricConverter(miles, km){
let total = km / miles;
return total
}
console.log(0.621, 1);





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


function feetConverter (ft, cm){
let total = ft / cm;
return total
}
console.log(12, 36);



Expand Down Expand Up @@ -111,8 +178,3 @@
/************************************************************** Stretch **************************************************************/
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object