diff --git a/exercises.js b/exercises.js index 2f86f9d..9d9b29b 100644 --- a/exercises.js +++ b/exercises.js @@ -1,6 +1,7 @@ /* If statements - Evaluates (or checks) a condition. If the condition is true, any statements in the subsequent code block are executed */ + /*var today = new Date(); if(today === "Friday"){ @@ -17,7 +18,6 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true return "Get back to coding!"; };*/ - /* * #1 * Function - canVote @@ -29,6 +29,17 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * The function will return true if the number passed into the function is equal to or greater than Hawaii's voting age. Console.log your result. */ +/*function canVote(age){ + if (age >= 18){ + return true; + } else { + return false; + } +} + +console.log('canVote:', canVote(15)); +console.log('canVote:', canVote(19));*/ + /* * #2 @@ -42,6 +53,17 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * Console.log your result. */ +/*function login(password){ + if(password === 'test1234'){ + return 'Login Success!'; + } else { + return 'Login Fail!'; + } +} + +console.log('login:', login('test1234')); +console.log('login:', login('test4321'));*/ + /* * #3 @@ -56,6 +78,16 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * Console.log your result. */ +/*function isGreaterThan(first, second){ + if(first > second){ + return true; + } else { + return false; + } +} + +console.log('Is Greater Than:', isGreaterThan(2,1)); +console.log('Is Greater Than:', isGreaterThan(1,2));*/ /* @@ -70,6 +102,17 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * Console.log your result. */ +/*function mustbeTrue(boo){ + if(boo === true){ + return true; + } else { + return false; + } +} + +console.log('mustbeTrue:', mustbeTrue(true)); +console.log('mustbeTrue:', mustbeTrue(false));*/ + /* @@ -80,10 +123,20 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * @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. + * 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. */ +/*function bigBird(word){ + if(word === word.substring(0,3)){ + return 'Word to Big Bird'; + } else { + return 'Nah'; + } +} + +console.log(bigBird('che'));*/ + /* @@ -95,7 +148,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * @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." + * 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. */ @@ -109,7 +162,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * @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." + * 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. */ @@ -124,7 +177,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * 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. -*/ +*/ @@ -140,7 +193,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * 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. -*/ +*/ @@ -154,7 +207,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * The function will return true if the number passed in is an even integer, otherwise it will return false. * Console.log your result. -*/ +*/ @@ -170,7 +223,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * 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. -*/ +*/ /* @@ -184,7 +237,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * 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. -*/ +*/ @@ -198,7 +251,7 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * 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. -*/ +*/ /* @@ -210,10 +263,31 @@ If/else statements = Evaluates (or checks) a condition. If the condition is true * * 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. + * Your function should return a message 'Not enough money' if you run out of money in your budget * Console.log budget and doughnutBought. * Invoke your function again. * Console.log budget and doughnutBought again. -*/ +*/ + +/*var budget = 20; +var doughnutPrice = 5; +var doughnutBought = 0; + +function buyDoughnut(){ + if (budget >= doughnutPrice){ + budget = budget - doughnutPrice; + return doughnutBought++; + } else { + return 'not enough funds'; + } +} + +console.log(budget); +console.log(doughnutBought); +buyDoughnut(); +console.log(budget); +console.log(doughnutBought); +*/ @@ -236,7 +310,7 @@ for (var i = 0; i