Learn String Manipulation by Building a Cipher - Step 16

Tell us what’s happening: After finding the value of text[0] in alphabet and then assigning it to index, then using print(index), the terminal returned 7, as the h in “hello world” is the 7th value in the alphabet. Now I have to 'find the letter at index 7 plus the value of shift." It told me to declare a new variable named “shifted” and assign it to the alphabet letter at index plus shift.

I’m completely lost. What is this and what do I do?

Your code so far


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
shifted = 

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 16

Do you remember how to access a letter position of a string? text[0] accesses the letter at the first (0) position of text.

You want to access a letter in the string alphabet at the position index + shift

Try these steps:

  • declare a variable named shifted and assign it the string alphabet
  • modify the assignment into alphabet at position index using square brackets
  • modify the position in the square brackets to index + shift

You know if you want to access the h in alphabet would be alphabet[7] since you already found the position. Now you want to slide 3 (stored in the shift variable) letters down the alphabet from h and get that letter.

The challenge is quite simple. All that need to be done is to assign shifted variable a string variable that is generated by adding the index variable and shift integer to the alphabet variable to get the new variable index.

MOD EDIT: Solution removed.

Hi there and welcome to our community!
We are trying to avoid spoilers and solutions on the forum, so please only offer guidance and hints if you wish to help other Campers with challenges.

Use the format variable = string[var1 + var2]

First step is to declare your variable shifted.

Second, you have already solved for the index of h in alphabet (index = 7), and now you want to shift that by the value of your shift variable (in this case 3), but you want to do this in relation to the alphabet variable itself. Create your algorithm to shift the index (x + y), where x is your initial index and y is your shift. This is your new index equation that can be placed in the index value in alphabet.

This camper has to wonder if it might be more helpful if the spoiler or solution was posted. Detailing the challenge exactly and efficiently vs. reading through various random forum comments.

Much gratitude to all at freeCodeCamp.org

This thread is a bit old and this project has been re-organized since then, so this thread no longer applies to this question.

If you have a question please open a new thread, thanks!