What you will use in this project
- let and const
- Conditionals and loops
- String and number methods
- Writing pure return-value functions
In script.js:
addNumbers stub.a + b.return, not console.log.One line: return a + b;.
Refresher: JS Functions.
s with the first letter upper-cased."kai" becomes "Kai".In script.js:
s.charAt(0).toUpperCase().s.slice(1).+.Edge case: if s is empty, return "" so the helper does not crash.
Strings have a .toUpperCase() method.
See JS String Methods.
s with its characters in reverse order."hello" becomes "olleh".In script.js:
let result = "".for (let i = s.length - 1; i >= 0; i--).result += s.charAt(i).result.The point is the for loop.
Do not use .split("").reverse().join("").
true if s reads the same forwards and backwards.In script.js:
s first with const lower = s.toLowerCase().reverseString.Edge case: an empty string reads the same forwards and backwards, so it returns true naturally.
You can call your own helpers.
Example: return lower === reverseString(lower);.
s.In script.js:
let count = 0.for (let i = 0; i < s.length; i++)."aeiouAEIOU".indexOf(s.charAt(i)) !== -1.count++.count.indexOf returns -1 when the character is not in the lookup string.
init() so each function result shows up on the page.In script.js:
init(), read each input constant at the top of the file.textContent.addNumbers writes to #r-add.capitalize writes to #r-cap.reverseString writes to #r-rev.isPalindrome writes to #r-pal.countVowels writes to #r-vow.Use document.getElementById("r-add").textContent = String(addNumbers(NUM_A, NUM_B));.
See DOM textContent.