forked from CodeNextCoaches/te2018grade9term1
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathnumbers.js
89 lines (62 loc) · 3.6 KB
/
numbers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const READLINE = require("readline-sync");
/******************************************************************************
printGreeting()
Prints a simple greeting. Be as creative as you want here. Be sure to include
your name as the author!
*******************************************************************************/
/******************************************************************************
sayOneNine(num)
This function takes a number between 1 and 9 (inclusive) as input and returns
that same number in word form. If the number is not between 1 and 9, the
function returns an empty string, which is just "".
Examples:
sayOneNine(5) → "five"
sayOneNine(8) → "eight"
sayOneNine(13) → ""
*******************************************************************************/
/******************************************************************************
sayTenNineteen(num)
This function takes a number between 10 and 19 (inclusive) as input and returns
that same number in word form. If the number is not between 10 and 19, the
function returns an empty string, which is just "".
Examples:
sayTenNineteen(11) → "eleven"
sayTenNineteen(15) → "fifteeen"
sayTenNineteen(25) → ""
*******************************************************************************/
/******************************************************************************
sayTwentyNinety(num)
This function takes a number between 2 and 9 (inclusive) as input and returns
that same number in word form, but in the tens place. If the number is not
between 2 and 9, the function returns an empty string, which is just "".
Examples:
sayTwentyNinety(5) → "fifty"
sayTwentyNinety(8) → "eighty"
sayTwentyNinety(1) → ""
*******************************************************************************/
/******************************************************************************
sayNumber(num)
This function calls the three functions above to convert an entire number (num)
into word form, then returns that word. This function should be able to handle
numbers from 0 to 9999 (inclusive).
To do this, first declare a variable named wordForm at the top of the
function. This will be the string you will return at the end of the function,
so initialize it to an empty string at the start: let wordForm = "";
Your first conditional statement should check if num is equal to 0. If so,
set wordForm to the string "zero".
Otherwise, build the word form of num by chopping num into thousands,
hundreds, tens, and ones. Convert each place value number to a word by calling
the three functions above, and concatenate each word with the wordForm variable.
At the very end of your function it should simply return wordForm.
Examples:
sayNumber(0) → "zero"
sayNumber(9999) → "nine-thousand nine-hundred ninety-nine"
sayNumber(75) → "seventy-five"
*******************************************************************************/
/******************************************************************************
run()
This function simply runs your program. At the very least it should greet the
user, ask the user to enter a number between 0 and 9999, then print that
number in word form.
*******************************************************************************/
// Call run() below to run your program!