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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// 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": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@ The module challenge is the afternoon project or assignment that students work t
- write a basic for loop / while loop.
- write control flow using if/else statements.
- use function declarations, expressions, and arrow
functions and describe their differences
functions and describe their differences

## Introduction

Today you'll worth through 7 JavaScript Tasks to practice today's objectives and get familiar and comfortable with the foundations of JavaScript.
Today you'll worth through 7 JavaScript Tasks to practice today's objectives and get familiar and comfortable with the foundations of JavaScript.

Exercises are outlined in the `index.js` file, please read the instructions carefully for each task and complete it. Note that you may have to use your googling skills to research and look things up if you do not have all the information you need to complete the task.


## Instructions

### Task 1: Set up Project

Using VSCode and Command Line:

1. Fork repo and add TL as collaborator on Github.
2. Clone your fork (not Lambda's repo by mistake!).
3. `cd` into your newly cloned repository.
4. Create a new branch by typing `git checkout -b <firstName-lastName>`.
1. x Fork repo and add TL as collaborator on Github.
2. x Clone your fork (not Lambda's repo by mistake!).
3. x `cd` into your newly cloned repository.
4. x Create a new branch by typing `git checkout -b <firstName-lastName>`.

### Task 2: Complete MVP Requirements

Find the `index.js` file and complete the tasks as written.
Find the `index.js` file and complete the tasks as written.

As you work on your code you should make use of `console.log` to check your progress and debug.

Expand All @@ -49,7 +48,7 @@ The completion of these questions is mandatory for MVP. However, passing the qui

After you have completed the requirements, try any of the following challenges. As always, note that these may require additional research beyond what you learned in this module.

- [ ] See tasks labelled stretch. Please ensure you've completed MVP before you attempt the stretch goals. Note that you may need to look forward to tomorrow's training kit in order to complete the task.
- [ ] See tasks labelled stretch. Please ensure you've completed MVP before you attempt the stretch goals. Note that you may need to look forward to tomorrow's training kit in order to complete the task.

## Submission format

Expand All @@ -62,4 +61,3 @@ Follow these steps for completing your project.
## Resources

🧮 [Polya's 4 Step Approach to Problem Solving](http://web.mnstate.edu/peil/M110/Worksheet/PolyaProblemSolve.pdf)

175 changes: 132 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,207 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)

const votingAge = 38;



if (votingAge > 18) {
console.log("True, yes, you can vote.");
} else {
console.log("False, no, you can't vote. Sorry.");
}

//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 num1 = 1;

const num2 = 2;

if (num2 === 2) {
num1 = num1 + num2;
}

console.log("Your number is " + num1);

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

let date1 = "1999";

date1 = Number(date1);

console.log("Your date is " + date1);

//Test should = 2000

//Task d: Write a function to multiply a*b
console.log("Your date + 1 is " + (date1 + 1));

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

function multiply(a, b) {
return a * b;
}

num1 = multiply(num1, num2);

console.log("Your number is " + num1);

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


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

console.log(
votingAge + " is equal to " + dogYears(votingAge) + " in dog years"
);

/************************************************************** Task 3 **************************************************************/
//Dog feeder
//Dog feeder
//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
// adult dogs at least 1 year
// up to 5 lbs - 5% of their body weight
// 6 - 10 lbs - 4% of their body weight
// 11 - 15 lbs - 3% of their body weight
// > 15lbs - 2% of their body weight
// 6 - 10 lbs - 4% of their body weight
// 11 - 15 lbs - 3% of their body weight
// > 15lbs - 2% of their body weight

// Puppies less than 1 year
// 2 - 4 months 10% of their body weight
// 4 - 7 months 5% of their body weight
// 4 - 7 months 5% of their body weight
// 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(a, b) {
if (b >= 1 && a > 15) {
return a * 0.02;
} else if (b >= 1 && a >= 11 && a <= 15) {
return a * 0.03;
} else if (b >= 1 && a >= 6 && a < 11) {
return a * 0.04;
} else if (b > 0.84 && b < 1) {
return a * 0.05;
} else if (b >= 0.48 && b < 0.84) {
return a * 0.04;
} else if (b > 0.48 && b < 0.24) {
return a * 0.05;
} else {
return a * 0.1;
}
}

const dogPounds = 15;

const dogYear = 1;

let dogFood = dogFeeder(dogPounds, dogYear);

console.log("Your dog should eat " + dogFood + " lbs of dog food every day.");

/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
// Your function should take a string (either rock paper or sissors)
// 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



// 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 rockPaperScissors(p, c) {
if (p === 0 && c === 0) {
return "You picked rock and your opponent picked rock, you tied";
} else if (p === 0 && c === 1) {
return "You picked rock and your opponent picked paper, you lose";
} else if (p === 0 && c === 2) {
return "You picked rock and your opponent picked scissors, you win";
} else if (p === 1 && c === 0) {
return "You picked paper and your opponent picked rock, you win";
} else if (p === 1 && c === 1) {
return "You picked paper and your opponent picked paper, you tied";
} else if (p === 1 && c === 2) {
return "You picked paper and your opponent picked scissors, you lose";
} else if (p === 2 && c === 0) {
return "You picked scissors and your opponent picked rock, you lose";
} else if (p === 2 && c === 1) {
return "You picked scissors and your opponent picked paper, you win";
} else {
return "You picked scissors and your opponentr picked scissors, you tied";
}
}

const computerChoice = Math.floor(Math.random() * 3);

const personChoice = 1;

let outcome = rockPaperScissors(personChoice, computerChoice);

console.log(outcome);

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

function kmToMiles(a) {
return a * 0.6214;
}



console.log(num1 + "km is equal to " + kmToMiles(num1) + " miles");

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



function ftToCm(a) {
return a * 30.48;
}

console.log(num1 + " feet/foot is equal to " + ftToCm(num1) + " centimeters");

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

console.log(annoyingSong());

/************************************************************** Task 7 **************************************************************/
//Grade Calculator
//write a javaScript program that takes a mark out of 100 and returns a corisponding letter grade
//90s should be A
//80s should be B
//70s should be Cs
//60s should be D
//write a javaScript program that takes a mark out of 100 and returns a corisponding letter grade
//90s should be A
//80s should be B
//70s should be Cs
//60s should be D
//and anything below 60 should be F




const gradeNum1 = 83.161;

if (gradeNum1 >= 90) {
console.log("Your grade is A");
} else if (gradeNum1 >= 80) {
console.log("Your grade is B");
} else if (gradeNum1 >= 70) {
console.log("Your grade is C");
} else if (gradeNum1 >= 60) {
console.log("Your grade is D");
} else {
console.log("Your grade is F");
}

/************************************************************** 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
// Hint - you may need to study tomorrow's traning kit on arrays
// try looking up the .includes() method





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