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
4 changes: 4 additions & 0 deletions exercises/201-hello-world.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
43 changes: 43 additions & 0 deletions exercises/205-tip-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}




// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -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);
}
}




// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -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;
}
}

37 changes: 37 additions & 0 deletions exercises/208-predicate-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -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;
}
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -53,3 +78,15 @@
// isCapitalCity('Texas', 'Houston') --> false
// isCapitalCity('Alaska', 'Juneau') --> true
// isCapitalCity('Strawberry', 'Mango') --> false












16 changes: 16 additions & 0 deletions exercises/210-fizzbuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ".";
}

29 changes: 29 additions & 0 deletions exercises/211-rock-paper-scissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}