Code of the Day
BeginnerLanguage basics

Lab: logic and text

Practice functions, control flow, and string methods by building small utilities.

Lab · optionalJavaScript / TSBeginner15 min
By the end of this lesson you will be able to:
  • 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:

JavaScript — editable, runs in your browser

Checkpoint 1 — count the vowels

Write countVowels to return how many vowels (a, e, i, o, u, any case) a string contains.

Count the vowelsJavaScript

Write countVowels(str) returning the number of vowels (a, e, i, o, u; upper or lower case).

countVowels('hello')2

A 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.

Detect a palindromeJavaScript

Write isPalindrome(str) returning true if the string reads the same forwards and backwards, ignoring case.

isPalindrome('racecar')trueisPalindrome('hello')false

Reversing 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.

Finished reading? Mark it complete to track your progress.

On this page