1/*We'll start by initializing two variables: the string we want to
2reverse, and a variable that will eventually store the reversed value
3of the given string.*/
4
5let str = "blue";
6let reversed = "";
7
8/*Here, reversed is our accumulator variable. Our approach to reversing
9the string will be to loop over str, adding each subsequent character
10to the beginning of reversed, so that the first character becomes the
11last, and the last character becomes the first.*/
12
13let str = "blue";
14let reversed = "";
15
16for (let i = 0; i < str.length; i++) {
17 reversed = str[i] + reversed;
18}
19
20console.log(reversed);
21
22//eulb