#todo
Which line can be placed in the blank to make a loop that mirrors the input? There may be more than 1 correct answer!
'use strict';
let text = 'abc';
let mirrored = '|';
for (let char of text) {
__;
}
console.log(mirrored); // 'cba|abc'
A: let mirrored = char + mirrored;
✖ Nope.
Close! This is line contains one half of the correct solution.
This is how you reverse a string. The characters from "abc"
will be added in
order to the front of the mirrored
string. The final log will be:
"cba|"
B: mirrored = mirrored + char;
✖ Nope.
Close! This is line contains one half of the correct solution.
This line of code will just rebuild the original text one character at a time, adding each one to the end of the growing string. The final log will be:
"|abc"
C: mirrored = char + mirrored + char;
✔ Correct!
With each iteration, this line of code will add the same character to both end
of the mirrored
string. The final result will be a string with the reversed
text on the left, and the original text on the right:
"cba|abc"
D: mirrored = mirrored + char + mirrored;
✖ Nope.
Much cooler, but not correct. Can you figure out why the final log looks like this?
"|a|b|a|c|a|b|a|"