From b27e4fc7ca8241164fc95d842e62f1feb0b744d3 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 13 Mar 2017 11:19:07 -1000 Subject: [PATCH] updated exercises --- exercises.js | 19 ++- solutions.js | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 484 insertions(+), 5 deletions(-) create mode 100644 solutions.js diff --git a/exercises.js b/exercises.js index e0d51c7..171bec3 100644 --- a/exercises.js +++ b/exercises.js @@ -57,6 +57,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + /* * #4 * Function - mustBeTrue @@ -70,6 +71,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + /* * #5 * Function - bigBird @@ -83,6 +85,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + /* * #6 * Function - isEqual @@ -124,6 +127,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + /* * #9 * Function - dirty30 @@ -139,6 +143,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + /* * #10 * Function - evenStevens @@ -152,6 +157,8 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + + /* * #11 * Function - daClub @@ -180,6 +187,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + /* * #13 * Function - moneyTrain @@ -208,6 +216,9 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true */ + + + /* For loops - A for loop checks a condition a specific number of times and allows us to execute a code block and evaluate a condition to determine if our loop should run again. @@ -259,6 +270,7 @@ for (var i = 0; i= 18){ + return true; + }else{ + return false; + } +} +console.log("1. canVote: ", canVote(19)); + + + +/* + * #2 + * Function - login + * Create a function named `login` which will take a parameter: `password`. + * + * @param Datatype: String `password` + * @return Datatype: String + * + * The function will return the message: "Login Success!", if the string passed into the function is "test1234" + * Console.log your result. +*/ + +function login(password){ + if(password === "test1234"){ + return "Login Success!"; + } +} + +console.log(login("test1234")); +/* + * #3 + * Function - isGreaterThan + * Create a function named `isGreaterThan` which will take two parameters: `first` and `second` + * + * @param Datatype: Number `first` + * @param Datatype: Number `second` + * @return Datatype: Boolean + * + * The function will return true if the first number is greater than the second. + * Console.log your result. +*/ + +function isGreaterThan(first, second){ + if(first > second){ + return true; + } +} + +console.log(isGreaterThan(3, 1)); + +var showResult = isGreaterThan(5, 1); +console.log(showResult); + +/* + * #4 + * Function - mustBeTrue + * Create a function named `mustBeTrue` which will take a parameter: `boo`. + * + * @param Datatype: Boolean `boo` + * @return Datatype: Boolean + * + * The function will return true if the value passed into the function is "true". + * Console.log your result. +*/ + +function mustBeTrue(boo){ + if(boo === true){ + return true; + }else{ + return false; + } + +} + +console.log(mustBeTrue(true)); + +/* + * #5 + * Function - bigBird + * Create a function named `bigBird` which will take a parameter: `word`. + * + * @param Datatype: String `word` + * @return Datatype: String + * + * The function will return the message "Word to Big Bird!", if the string passed into the function is a three-letter word. + * Console.log your result. +*/ + +var arr = ["apple", "banana", "orange"]; + +function bigBird(word){ + if(word.length === 3){ + return "Word to Big Bird!"; + } +} + +console.log(bigBird(arr)); + +/* + * #6 + * Function - isEqual + * Create a function named `isEqual` which takes two parameters: `first` and `second`. + * + * @param Datatype: String `first` + * @param Datatype: String `second` + * @return Datatype: String + * + * If the strings are equal, the function will return the message "You look mahvelous!" Otherwise, return the message: "I don't know who you are anymore." + * Console.log your result. +*/ + + +/* + * #7 + * Function - notEqual + * Create a function named `notEqual` which takes two parameters: `first` and `second`. + * + * @param Datatype: String `first` + * @param Datatype: String `second` + * @return Datatype: String + * + * If the strings are not equal, the function will return the message "Opposites do attract." Otherwise, return the message: "Cause it's like you're my mirror." + * Console.log your result. +*/ + + +/* + * #8 + * Function - spareChange + * Create a function named `spareChange` which takes a parameter: `money`. + * + * @param Datatype: Number `money` + * @return Datatype: Boolean + * + * The function will return true if the number passed into the function is greater than 100, otherwise it will return false. + * Console.log your result. +*/ + + + + + +/* + * #9 + * Function - dirty30 + * Create a function named `dirty30` which takes three parameters: `one`, `two` and `three`. + * + * @param Datatype: Number `one` + * @param Datatype: Number `two` + * @param Datatype: Number `three` + * @return Datatype: Boolean + * + * The function will return true if the sum of all the number values is greater than 30, otherwise it will return false. + * Console.log your result. +*/ + + + +/* + * #10 + * Function - evenStevens + * Create a function named `evenStevens` which takes a parameter: `num`. + * + * @param Datatype: Number `num` + * @return Datatype: Boolean + * + * The function will return true if the number passed in is an even integer, otherwise it will return false. + * Console.log your result. +*/ + +function evenStevens(num){ + if(num%2 === 0){ + return true; + }else{ + return false; + } +} + +console.log("evenStevens ", evenStevens(8)); + + + +/* + * #11 + * Function - daClub + * Create a function named `daClub` which takes two parameters: `cover` and `age`. + * + * @param Datatype: Number `cover` + * @param Datatype: Number `age` + * @return Datatype: String + * + * If BOTH values are 21 or over, the function will return the message: "Welcome to the Legends Lounge." Otherwise, it will return the message: "Chuck E Cheese is across the street." + * Console.log your result. +*/ + + +/* + * #12 + * Function - graduation + * Create a function named `graduation` which takes two parameters: `credits` and `thesis`. + * + * @param Datatype: Number `credit` + * @param Datatype: Boolean `thesis` + * @return Datatype: String + * + * If EITHER the number value is greater than or equal to 120 or the boolean value is true, then the function will return the message: "Congratulations on a job well done." Otherwise, return the message: "See you in summer school." + * Console.log your result. +*/ + +function graduation(credits, thesis){ + if(credits >= 120 || thesis){ + return "Congratulations on a job well done."; + }else{ + return "See you in summer school."; + } + +} + +var gradResults = graduation(120, true); +console.log(gradResults); + +/* + * #13 + * Function - moneyTrain + * Create a function named `moneyTrain` which takes a parameter: `speed`. + * + * @param Datatype: Number `speed` + * @return Datatype: String + * + * The function will return the message: "You are riding Honolulu's Rail.", if the number value is less than 50, otherwise it will return the message: "You are riding an Amtrak.", if the number value is less than 100, and return the message: "Now you ballin' in the Shinkansen!", if the number value is greater than or equal to 100. + * Console.log your result. +*/ + + +/* + * #14 + * Function - buyDoughnut + * Declare a variable named `budget` and assign it with a number value that is greater than 20. + * Declare a variable named `doughnutPrice` and assign it with a number value that is greater than 0 but less than 6. + * Declare a variable named `doughnutBought` and assign it with a number value of 0. + * + * Create a function named `buyDoughnut` which takes NO parameters. + * When the function is invoked, the budget will be decreased by the doughnutPrice and doughnutBought will increase by 1. + * Console.log budget and doughnutBought. + * Invoke your function again. + * Console.log budget and doughnutBought again. +*/ + +var budget = 100; +var doughnutPrice = 5; +var doughnutBought = 0; + +function buyDoughnut(){ + if(budget >= doughnutPrice){ + budget = budget - doughnutPrice; + //budget -= doughnutPrice; + doughnutBought++; + } +} + + +console.log("budget ", budget); +console.log("bought ", doughnutBought); + + + +/* +For loops - A for loop checks a condition a specific number of times and allows us to execute a code block and evaluate a condition to determine if our loop should run again. + +The for loop is made up for 3 parts: + +1) Initialization (i.e. var i = 0;) +2) Condition (i.e. i