This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function helloWorld(lang_type) { | |
| if (lang_type == 'en') { | |
| return "hello world!" | |
| } else if (lang_type == 'es') { | |
| return "hola mundo" | |
| } else if (lang_type == 'fr') { | |
| return "bonjour tout le monde" | |
| } | |
| } | |
| console.log(helloWorld('fr')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function assignGrade(num_score) { | |
| if (num_score >= 90) { | |
| return "A"; | |
| } else if (num_score >= 80 && num_score <= 90) { | |
| return "B"; | |
| } else if (num_score >= 70 && num_score <= 80) { | |
| return "C"; | |
| } else if (num_score >= 60 && num_score <= 70) { | |
| return "D"; | |
| } else if (num_score <= 60) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function pluralizer(noun, number) { | |
| if (number == 1) { | |
| if (noun == 'geese') { | |
| return "" + number + " goose."; | |
| } | |
| else { | |
| return "" + number + " " + noun + ""; | |
| } | |
| } else | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function greaterNum(num1, num2){ | |
| if (num1 > num2) { | |
| return num1 + " is greater than " + num2; | |
| } else { | |
| return num2 + " is greater than " + num1; | |
| } | |
| } | |
| console.log(greaterNum(20, 32)) | |
| console.log(greaterNum(60, 32)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (var current = 0; current <= 20; current++) { | |
| if (current % 2 == 0) { | |
| console.log('even: ' + current); | |
| } else { | |
| console.log('odd: ' + current); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var color = ['blue', 'yellow', 'black'] | |
| var presidents = ['clinton', 'obama', 'bush'] | |
| var whatever = ['cats', 'dogs', 'hot sause'] | |
| for (i = 0; i < color.length; i++) { | |
| console.log( i + " is a color I like " + color[i]) | |
| console.log( i + " president: " + presidents[i]) | |
| console.log( i + " random list " + whatever[i]) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function drEvil(money_amount) { | |
| if (money_amount > 100000) { | |
| return money_amount + " dollars (pinky)"; | |
| } else { | |
| return money_amount + " dollars"; | |
| } | |
| } | |
| console.log(drEvil(10)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mixUp(word, other_word) { | |
| return other_word.slice(0, 2) + word.slice(2) + " " + word.slice(0, 2) + other_word.slice(2); | |
| } | |
| console.log(mixUp('cat', 'dog')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function squareNumber(num) { | |
| return "The result of squaring the number " + num + " is " + num*num; | |
| } | |
| console.log(squareNumber(3)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function percentOf(num1, num2) { | |
| n = num1/num2*100; | |
| return num1 + " is " + Math.round(n) + " % of " + num2; | |
| } | |
| console.log(percentOf(2, 4)); |
OlderNewer