JavaScript bootcamp · Lab 15

Palindrome check

mediumStrings10 minLesson: Strings

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read one word and log yes if it reads the same forwards and backwards, otherwise no.

Ignore case: Level should count as a palindrome.

Input. One line: a word.

Output. yes or no (lowercase).

Examples

Example 1 — Case-insensitive.
Input
Level
Output
yes
Example 2
Input
python
Output
no
Hint
  1. Lowercase first so case does not break the comparison.
  2. Compare the word to its reversed form.
Show correct code

Peek only after you have tried. You can still Check your own version.

const s = readLine().trim().toLowerCase();
const rev = [...s].reverse().join("");
console.log(s === rev ? "yes" : "no");
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.