×
Your assignment is to write the following functions in the descriptions below - good luck!
difference
difference(2,2); // 0 difference(0,2); // -2
product
product(2,2); // 4 product(0,2); // 0
printDay
printDay(4); // "Wednesday" printDay(41); // undefined
lastElement
undefined
if the array is empty.lastElement([1,2,3,4]); // 4 lastElement([]); // undefined
numberCompare
numberCompare(1,1); // "Numbers are equal" numberCompare(2,1); // "First is greater" numberCompare(1,2); // "Second is greater"
singleLetterCount
singleLetterCount('amazing','A'); // 2 singleLetterCount('Rithm School','o'); // 2
multipleLetterCount
multipleLetterCount("hello"); // {h:1, e: 1, l: 2, o:1} multipleLetterCount("person"); // {p:1, e: 1, r: 1, s:1, o:1, n:1}
arrayManipulation
arrayManipulation([1,2,3], "remove", "end"); // 3 arrayManipulation([1,2,3], "remove", "beginning"); // 1 arrayManipulation([1,2,3], "add", "beginning", 20); // [20,1,2,3] arrayManipulation([1,2,3], "add", "end", 30); // [1,2,3,30]
isPalindrome
true
or false
if it is a palindrome. As a bonus, allow your function to ignore whitespace and capitalization so that isPalindrome('a man a plan a canal Panama');
returns true
isPalindrome('testing'); // false isPalindrome('tacocat'); // true isPalindrome('hannah'); // true isPalindrome('robert'); // false
Rock / Paper / Scissor
prompt
function, a user can enter their choice and based on a random selection - they can either tie/win or lose against a computer.You can find the code to all solutions here
When you're ready, move on to Nested Objects