diff --git a/exercises/201-hello-world.js b/exercises/201-hello-world.js index b84d923..e68611b 100644 --- a/exercises/201-hello-world.js +++ b/exercises/201-hello-world.js @@ -9,3 +9,7 @@ // Write a function "helloDefault" such that if no name is given it will return // 'Hello, world!' // Otherwise it behaves the same as the "hello" function. + +function hello (name) { + alert ("Hello, " + name); +} diff --git a/exercises/205-tip-calculator.js b/exercises/205-tip-calculator.js index 24c4f99..f88da10 100644 --- a/exercises/205-tip-calculator.js +++ b/exercises/205-tip-calculator.js @@ -10,6 +10,20 @@ // tipAmount(100, 'good') --> 20 // tipAmount(40, 'fair') --> 6 +var tipAmount = function(bill,service) { + var tip; + if (service = "good") { + tip *=bill*0.2; + } + else if (service = "fair") { + tip *=bill*0.15; + } + else { + tip *=bill*0.1; + } +} + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -21,6 +35,20 @@ // totalAmount(100, 'good') --> 120 // totalAmount(40, 'fair') --> 46 +var totalAmount = function(bill,service) { + var total; + if (service = "good") { + total = bill + tipAmount(bill,service); + } + else if (service = "fair") { + total = bill + tipAmount(bill,service); + } + else { + total = bill + tipAmount(bill,service); + } +} + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -31,3 +59,18 @@ // Examples: // splitAmount(100, 'good', 5) --> 24 // splitAmount(40, 'fair', 2) --> 23 + + +var splitAmount = function(bill,service,people) { + var split; + if (service="good") { + split = (bill + tipAmount(bill,service))/people; + } + else if(service="fair") { + split = (bill + tipAmount(bill,service))/people; + } + else { + split = (bill + tipAmount(bill,service))/people; + } +} + diff --git a/exercises/208-predicate-functions.js b/exercises/208-predicate-functions.js index ac33924..f6c992d 100644 --- a/exercises/208-predicate-functions.js +++ b/exercises/208-predicate-functions.js @@ -21,6 +21,14 @@ // isVowel(99) --> false // isVowel({e: 'Elephant'}) --> false +var isVowel = function(char) { + if (char === 'a' || char === 'e' ) || char === 'i' || char === 'o' ) || char === 'u' ) { + return true; + } + else { + return false; + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -36,7 +44,24 @@ // isOdd(5) --> true // isOdd('7') --> false // isOdd(3.14) --> false + + var isEven = function(num) { + if (num%2 == 0) { + return true; + } + else { + return false; + } + } + var isOdd = function(num) { + if (num%2 == 1) { + return true; + } + else { + return false; + } + } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -53,3 +78,15 @@ // isCapitalCity('Texas', 'Houston') --> false // isCapitalCity('Alaska', 'Juneau') --> true // isCapitalCity('Strawberry', 'Mango') --> false + + + + + + + + + + + + diff --git a/exercises/210-fizzbuzz.js b/exercises/210-fizzbuzz.js index 2ddfeba..2623056 100644 --- a/exercises/210-fizzbuzz.js +++ b/exercises/210-fizzbuzz.js @@ -9,3 +9,19 @@ // Examples: // fizzbuzz(3) --> '..fizz' // fizzbuzz(15) --> '..fizz.buzzfizz..fizzbuzz.fizz..fizzbuzz' + +var fizzbuzz = function(n) { + var str = []; + if (n%3 == 0 && n&5 == 0) { + return str = str + "fizzbuzz"; + } + else if (n%3 == 0 && n%5 != 0) { + return str = str + "fizz"; + } + else if (n%3 != 0 && n%5 == 0) { + return str = str + "buzz"; + } + else { + return str = str + "."; + } + diff --git a/exercises/211-rock-paper-scissors.js b/exercises/211-rock-paper-scissors.js index e3250fa..cfdac25 100644 --- a/exercises/211-rock-paper-scissors.js +++ b/exercises/211-rock-paper-scissors.js @@ -6,3 +6,32 @@ // rockPaperScissors('rock', 'scissors') --> 'player 1' // rockPaperScissors('rock', 'paper') --> 'player 2' // rockPaperScissors('paper', 'paper') --> 'draw' + +var rockPaperScissors = function(throw1,throw2) { + + if (throw1 == throw2) { + return = 'draw'; + } + else if (throw1 == 'rock' && throw2 == 'scissors') { + return = 'player1'; + } + else if (throw1 == 'rock' && throw2 == 'paper') { + return = 'player2'; + } + else if (throw1 == 'scissors' && throw2 == 'paper') { + return = 'player1'; + } + else if (throw1 == 'scissors' && throw2 == 'rock') { + return = 'player2'; + } + else if (throw1 == 'paper' && throw2 == 'scissors') { + return = 'player2'; + } + else if (throw1 == 'paper' && throw2 == 'rock') { + return = 'player1'; + } + + + + +