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: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ 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 the repo
2. Clone your forked version of the repo
3. cd into your repo and create a branch with your first and last name
Expand All @@ -38,14 +36,14 @@ Using VSCode and Command Line:

### Task 2: MVP

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

### Testing & Debugging

Open a second terminal inside of your project by clicking on the split terminal icon
![alt text](assets/split_terminal.png "Split Terminal")

Inside of your second terminal type `npm start`
Inside of your second terminal type `npm start`
![alt text](assets/npm_start.png "type npm start")

You will be running your tests in one terminal and debugging in the other. As you work on your code you should make use of `console.log` to check your progress and debug.
Expand All @@ -55,7 +53,7 @@ You will be running your tests in one terminal and debugging in the other. As yo

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.
- [x] 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 @@ -64,4 +62,3 @@ Please submit your project via codegrade by following [these instructions](https
## Resources

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

184 changes: 129 additions & 55 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Do the following:

HINT: no function required
*/


const votingAge = 21;
if (votingAge >= 18) {
console.log(true);
}

/*
Task 1b - Values
Expand All @@ -32,10 +34,12 @@ Do the following:

HINT: no function required
*/




let var1 = 1;
let var2 = 2;
if (var1 === 1) {
var1 = var2;
}
console.log(var1);

/*
Task 1c - Convert Strings to Numbers
Expand All @@ -47,9 +51,9 @@ Do the following:

HINT: look up the Number method
*/



let myNumString = "1999";
myNumString = parseInt(myNumString);
console.log(myNumString);

/*
Task 1d - Multiply
Expand All @@ -59,12 +63,11 @@ Do the following:
2. Receive the parameters: a and b
3. Multiply a and b and return the answer
*/

function multiply(/*add your code here*/){
/*add your code here*/
function multiply(a, b) {
const product = a * b;
return product;
}


console.log(multiply(5, 5));

/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -76,12 +79,11 @@ Do the following:
3. Return the newly calculated age
*/

function dogYears(/*add your code here*/){
/*add your code here*/
function dogYears(age) {
const ageInDogYears = age * 7;
return ageInDogYears;
}



/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

//Dog feeder - Depending on their weight and age, we need to know how many pounds of food to feed our dog each day!
Expand All @@ -107,14 +109,31 @@ Puppies less than 1 year
7 - 12 months 4% of their body weight

NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996
*/
*/

function hungryDog(/*add your code here*/){
/*add your code here*/
function hungryDog(weight, age) {
const isPuppy = age < 1;
if (isPuppy) {
if (age < 0.333) {
return weight * 0.1;
} else if (age >= 0.333 && age < 0.583) {
return weight * 0.05;
} else {
return weight * 0.04;
}
} else {
if (weight < 6) {
return weight * 0.05;
} else if (weight >= 6 && weight < 10) {
return weight * 0.04;
} else if (weight >= 10 && weight < 15) {
return weight * 0.03;
} else {
return weight * 0.02;
}
}
}



/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

// Rock, Paper, Scissors - Let's play against the computer!
Expand All @@ -125,7 +144,7 @@ Use Math.random to determine the computers choice (Math.random gives a random nu
HINT: While you can complete this with only conditionals based on strings, it may help to equate choice to a number when using Math.random()

Use the game function below to do the following:
1. Receive 2 parameters the user's choice and the computer's choice
1. Receive 2 parameters: the user's choice, and the computer's choice
2. Return whether the user won, lost, or tied based on these rules of the game described below - the strings returned need to match the strings below exactly.
- win should return "you win!"
- lose should return "you lose!"
Expand All @@ -136,29 +155,55 @@ RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors
HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters
*/

function game(user, computer){
/*add your code here*/
let computerChoice = Math.floor(Math.random(3));
function game(user, computer) {
// Computer Chose Rock
if (computer === "rock") {
if (user === "rock") {
return "it's a tie";
} else if (user === "paper") {
return "you win!";
} else {
return "you lose!";
}
}
// Computer Chose Paper
else if (computer === "paper") {
if (user === "rock") {
return "you lose!";
} else if (user === "paper") {
return "it's a tie";
} else {
return "you win!";
}
}
// Computer Chose Scissors
else {
if (user === "rock") {
return "you win!";
} else if (user === "paper") {
return "you lose!";
} else {
return "it's a tie";
}
}
}



/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

//Metric Converter
//Task 5a - KM to Miles
//Metric Converter
//Task 5a - KM to Miles
/*
Using the miles function below do the following:
1. Receive a number of kilometers
2. Convert the number of kiolmeters received to miles
3. Return the number of miles
*/

function miles(/*add your code here*/){
/*add your code here*/
function miles(kilometers) {
return kilometers * 0.621371;
}



//Task 5b - Feet to CM
/*
Using the feet function below do the following:
Expand All @@ -167,12 +212,10 @@ Using the feet function below do the following:
3. Return number of feet
*/

function feet(/*add your code here*/){
/*add your code here*/
function feet(centimeters) {
return centimeters / 30.48;
}



/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

// Let's Sing 99 Bottles of Soda on the Wall!
Expand All @@ -183,11 +226,22 @@ Using the annoyingSong function below do the following:
"{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(/*add your code here*/){
/*add your code here*/
function annoyingSong(startingNumber) {
let bottles = startingNumber;
let bottlesMinusOne = startingNumber - 1;
for (bottles = startingNumber; bottles > 0; bottles--) {
bottlesMinusOne = bottles - 1;
return (
bottles.toString() +
" bottles of soda on the wall, " +
bottles.toString() +
" bottles of soda, take one down pass it around " +
bottlesMinusOne.toString() +
" bottles of soda on the wall"
);
}
}


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

//Grade Calculator
Expand All @@ -203,12 +257,20 @@ Using the grade function below do the following:
below should return 'you got an F'
*/

function grade(/*Your Code here */){
/*Your Code here */
function grade(score) {
if (score > 89) {
return "you got an A";
} else if (score > 79 && score < 90) {
return "you got a B";
} else if (score > 69 && score < 80) {
return "you got a C";
} else if (score > 59 && score < 70) {
return "you got a D";
} else {
return "you got an F";
}
}



/*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/

//Vowel Counter - How many vowels are there?
Expand All @@ -221,17 +283,29 @@ HINT - you may need to study tomorrow's content on arrays
HINT - try looking up the .includes() method
*/


function vowelCounter(/*add your code here*/) {
/*add your code here*/
function vowelCounter(word) {
let numberOfLettersInWord = word.length;
let vowelCount = 0;
for (let index = 0; index < numberOfLettersInWord; index++) {
if (word.charAt(index) === "a" || word.charAt(index) === "A") {
vowelCount++;
} else if (word.charAt(index) === "e" || word.charAt(index) === "E") {
vowelCount++;
} else if (word.charAt(index) === "i" || word.charAt(index) === "I") {
vowelCount++;
} else if (word.charAt(index) === "o" || word.charAt(index) === "O") {
vowelCount++;
} else if (word.charAt(index) === "u" || word.charAt(index) === "U") {
vowelCount++;
}
}
return vowelCount;
}



/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/
function foo(){
console.log('its working');
return 'bar';
function foo() {
console.log("its working");
return "bar";
}
foo();
/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Don't touch the code after this line! 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/
Expand All @@ -244,5 +318,5 @@ module.exports = {
miles,
feet,
annoyingSong,
grade
}
grade,
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.