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 it reversed.
Strings have no reverse() method, but arrays do — so spread the string into characters first.
Input. One line: a word.
Output. The word, reversed.
Examples
Input
code
Output
edoc
Input
JS
Output
SJ
Hint
- [...word] makes an array of characters.
- Chain it: [...word].reverse().join("").
Show correct code
Peek only after you have tried. You can still Check your own version.
const word = readLine().trim();
console.log([...word].reverse().join(""));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.