Your friend Kojo is a big fan of numbers. He has a small website for playing around with numbers: www.fun-with-numbers.com. Kojo is not that good at programming so he asked you for help.
You will build two helper functions for new number games on Kojos' website and a third one to validate some input the user can enter.
One of the games on Kojos' website looks like a slot machine that shows two groups of wheels with digits on them. Each group of digits represents a number. For the game mechanics, Kojo needs to know the sum of those two numbers.
Write a function
twoSum that accepts two arrays as parameters.
Each array consists of one or more numbers between 0 and 9.
The function should interpret each array as a number and return the sum of those two numbers.
twoSum([1, 2, 3], [0, 7]); //=> 130 // [1, 2, 3] represents 123 and [0, 7] represents 7. // 123 + 7 = 130
Another game on the website is a little quiz called "Lucky Numbers". A user can enter a number and then sees whether the number belongs to some secret sequence or pattern. The sequence or pattern of the "lucky numbers" changes each month and each user only has a limited number of tries to guess it.
This months' lucky numbers should be numbers that are palindromes. Palindromic numbers remain the same when the digits are reversed.
Implement the new
luckyNumber function that accepts a number as parameter.
The function should return
true if the number is a palindrome and
The input number will always be a positive integer.
luckyNumber(1441); //=> true luckyNumber(123); //=> false
In various places on the website, there are input fields where the users can enter numbers and click a button to trigger some action. Kojo wants to improve the user experience of his site. He wants to show an error message in case the user clicks the button but the field contains an invalid input value.
Here is some more information on how the value of an input field is provided.
Write a function
errorMessage that accepts the user input as parameter.
If the user did not provide any input,
errorMessage should return
'Must be a number besides 0' should be returned.
In all other cases you can assume the input is valid, the return value should be an empty string.
errorMessage('123'); // => '' errorMessage(''); // => 'Required field' errorMessage('abc'); // => 'Must be a number besides 0'