Skip to content

Instantly share code, notes, and snippets.

@jonathanmarvens
Forked from rmurphey/gist:3164584
Last active December 20, 2015 01:59
Show Gist options
  • Save jonathanmarvens/6053526 to your computer and use it in GitHub Desktop.
Save jonathanmarvens/6053526 to your computer and use it in GitHub Desktop.

Problem 1

Use JavaScript to write a function that takes a number as its argument. If the number is less than 10, the function should return "small"; if the number is 10 or greater, but less than 100, the function should return "medium"; if the number is 100 or greater, the function should return "large".

Problem 2

Use JavaScript to write a function that takes a number as its argument. If the number is between 1 and 10 (inclusive), return the word for that number (that is, if the number passed to the function is 2, return the word "two"). If the number is not between 1 and 10, return false.

function numberNameIn1To10(number) {
var numbers = {};
numbers[1] = 'one';
numbers[2] = 'two';
numbers[3] = 'three';
numbers[4] = 'four';
numbers[5] = 'five';
numbers[6] = 'six';
numbers[7] = 'seven';
numbers[8] = 'eight';
numbers[9] = 'nine';
numbers[10] = 'ten';
if ((number >= 1) && (number <= 10)) {
return numbers[number];
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment