Back to Freecodecamp

Step 33

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6552487e689f6e895f658717.md

latest1.1 KB
Original Source

--description--

Now you need to create a new_char variable at the end of your loop body. Set its value to alphabet[new_index].

--hints--

You should create a new_char variable inside your for loop.

js
const commentless_code = __helpers.python.removeComments(code);
const {block_body} = __helpers.python.getBlock(commentless_code, /for\s+char\s+in\s+text\.lower\s*\(\s*\)\s*/);
assert(block_body.match(/new_char\s*=/));

You should set your new_char variable to alphabet[new_index] at the end of your loop body.

js
({test: () => {
    const commentless_code = __helpers.python.removeComments(code);
    const {block_body} = __helpers.python.getBlock(commentless_code, /for\s+char\s+in\s+text\.lower\s*\(\s*\)\s*/);
    assert(block_body.match(/new_char\s*=\s*alphabet\s*\[\s*new_index\s*\]\s*$/));
  }
})

--seed--

--seed-contents--

py
--fcc-editable-region--
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for char in text.lower():
    index = alphabet.find(char)
    print(char, index)
    new_index = index + shift
--fcc-editable-region--