Back to Freecodecamp

Step 29

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/65522255d5b9cd80f335c6f2.md

latest1.1 KB
Original Source

--description--

At the end of your loop body, declare a variable called new_index and assign the value of index + shift to this variable.

--hints--

You should declare a variable called new_index 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_index\s*=/));

You should assign index + shift to your new variable at the end of your for loop body.

js
({test: () => {
    const commentless_code = __helpers.python.removeComments(code);
    const {block_indentation, block_body} = __helpers.python.getBlock(commentless_code, /for\s+char\s+in\s+text\.lower\s*\(\s*\)\s*/);
    assert(block_body.match(/new_index\s*=\s*index\s*\+\s*shift\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)
--fcc-editable-region--