Bhaj's Crossword Helper explainer

Aim of the puzzle: Find the key information in a word problem and solve the problem using code.
Walk through of solution: Bhaj wants a function that takes a word and returns the last letter of the word.

Start the puzzle by adding a parameter to the lastLetter() function. Give it a name like word or something similar.

Create a local variable inside the function to store the last index value, for example: let lastIndex = word.length - 1.

Then, use this variable to return the last letter of the word, for example: return word[lastIndex]
Sample code solution:

import { randomWord } from 'cross.words';

function lastLetter(word) {
    let lastIndex = word.length - 1;
    return word[lastIndex];


Javascript Concepts: Functions, .length, Strings, Variables

1 Like

I solved it differently.
Here’s a screenshot, would there be any problem with my code since I didnt use the let declaration?

Nope! They are the same, and the function will have the same output whichever method you choose.

1 Like