Letter by Letter explainer

Aim of the puzzle: Use indexing with a string to access specific characters in the string.
Walk through of solution: Just like arrays, strings also have indexes, with each index representing a single character in a string (including spaces and symbols).

For example:

let string = 'bang!';

The 'b' is at string[0], the 'a' is at string[1], etc…

Also like arrays, strings have a .length property, that will return the number of characters (again, including spaces and symbols) in the string.

The string 'bang!' has a length of 5, as there are 5 characters total.

To complete this puzzle, add a parameter name to the function, for example: string.

Add a classic for loop to iterate through the input string, and inside the code block, use console.log() to print each character to the console.

Finally, call the function with a string to print each character to the console.

Sample code solution:

function printCharacters(string) {
    for ( let i = 0; i < string.length; i++) {
        console.log(string[i]);
    }
}

printCharacters('strings');


Javascript Concepts: Classic For Loops, Strings, Indexing, .length, console.log()