51 lines
1010 B
HTML
51 lines
1010 B
HTML
A function that takes a number from 0 to 5 and returns the
|
|
English word for that number. For example, 1 should return "one".
|
|
Hint: use an array to define the mapping from numbers to
|
|
strings.
|
|
<html><body><script>
|
|
function numdict (numb) {
|
|
dict = {
|
|
0 : "Zero",
|
|
1 : "One",
|
|
2 : "Two",
|
|
3 : "Three",
|
|
4 : "Four",
|
|
5 : "Five"
|
|
}
|
|
word = dict[numb]
|
|
console.log(word)
|
|
return word
|
|
}
|
|
|
|
let numberdictionary = function (numb) {
|
|
dict = {
|
|
0 : "Zero",
|
|
1 : "One",
|
|
2 : "Two",
|
|
3 : "Three",
|
|
4 : "Four",
|
|
5 : "Five"
|
|
}
|
|
word = dict[numb]
|
|
console.log(word)
|
|
return word
|
|
}
|
|
|
|
let nd = (numb) => {
|
|
dict = {
|
|
0 : "Zero",
|
|
1 : "One",
|
|
2 : "Two",
|
|
3 : "Three",
|
|
4 : "Four",
|
|
5 : "Five"
|
|
}
|
|
word = dict[numb]
|
|
console.log(word)
|
|
return word
|
|
}
|
|
|
|
numdict(1)
|
|
numberdictionary(2)
|
|
nd(3)
|
|
</script></body></html> |