challenges

Home / Reverse a String

Reverse a String

Write a function that will return the reverse of the value of the first parameter.

Function Scaffolding

/**
 * Reverses the value of the input.
 *
 * @param {string|number} input - The value to be reversed. Can be a string or a number.
 * @returns {string} The reversed string representation of the input.
 */
function reverseValue(input) {
    // ...
}

Possible Approach

  1. Create a function with one parameter. Have the function console.log() the input.
  2. Define an empty string variable called reverse to store the reversed string.
  3. Use a for loop to iterate through each character.
  4. Append each character to the beginning of the reverse variable.
  5. Return the contents of the reverse variable.

Assets

Download PDF Slide Desk