← Back to challenges

String Slice-athon

JavaScriptHardlanguage_fundamentalsstrings

Instructions

This challenge has five miniature exercises to help practice proficiency in string slicing. Check the examples below for a visual indicator of how to slice the strings. Good luck!

Examples

const s = "abcdefghijklmnopqrstuvwxyz"
challenge1(s) ➞ "abcde"
// First 5 characters of the string.

challenge2(s) ➞ "vwxyz"
// Last 5 characters of the string.

challenge3(s) ➞ "zyxwvutsrqponmlkjihgfedcba"
// All characters in the string from back.

challenge4(s) ➞ "fedcba"
// First 6 characters in the string (start with 6th character and go backwards).

challenge5(s) ➞ "tvxz"
// Take last 7 characters and only return odd positioned ones.

Notes

  • Check the Tests tab for more examples.
  • You may use methods other than slice() as needed to complete some of the challenges.
  • All test cases follow the same slicing pattern as the above example.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Promises II: What Is a Callback?