Skip to content

Instantly share code, notes, and snippets.

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'))
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) {
function pluralizer(noun, number) {
if (number == 1) {
if (noun == 'geese') {
return "" + number + " goose.";
}
else {
return "" + number + " " + noun + "";
}
} else
{
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))
for (var current = 0; current <= 20; current++) {
if (current % 2 == 0) {
console.log('even: ' + current);
} else {
console.log('odd: ' + current);
}
}
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])
}
function drEvil(money_amount) {
if (money_amount > 100000) {
return money_amount + " dollars (pinky)";
} else {
return money_amount + " dollars";
}
}
console.log(drEvil(10));
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'));
function squareNumber(num) {
return "The result of squaring the number " + num + " is " + num*num;
}
console.log(squareNumber(3));
function percentOf(num1, num2) {
n = num1/num2*100;
return num1 + " is " + Math.round(n) + " % of " + num2;
}
console.log(percentOf(2, 4));