Lab: logic and text
Practice functions, control flow, and string methods by building small utilities.
- Combine functions, loops, and string methods
- Reason about characters and case
- Make code pass a set of checks
Optional lab. Hands-on practice with the JavaScript basics — write it, run it, check it. These run in your browser instantly.
Warm up
Play with string methods before the graded parts:
Checkpoint 1 — count the vowels
Write countVowels to return how many vowels (a, e, i, o, u, any case) a string
contains.
Write countVowels(str) returning the number of vowels (a, e, i, o, u; upper or lower case).
countVowels('hello') → 2A clean approach: lower-case the string, then check each character against
'aeiou'.includes(ch).
Checkpoint 2 — palindrome?
Write isPalindrome to report whether a word reads the same forwards and
backwards, ignoring case.
Write isPalindrome(str) returning true if the string reads the same forwards and backwards, ignoring case.
isPalindrome('racecar') → trueisPalindrome('hello') → falseReversing a string is a three-step idiom: str.split('') to an array,
.reverse(), then .join('') back to a string. Lower-case first so case doesn't
matter.
Done?
Both green? You've combined loops, conditionals, and string methods into real functions. Next: arrays and objects — and a lab on shaping data with them.