Crosswords are puzzles that require the player to make intersecting words by filling in squares with letter
Notice we are missing one more word, but have some hints on certain letters placed in the mystery word
It will then output any possible words that match the length and letters given
The program we have so far will tell us adding question marks is an invalid input, like so:
The if statement needs to check if it's not a lowercase letter AND (the part you need to fill in) it's NOT a question mark
The question marks should now be valid input but they will be ignored when making anagrams
The indexOf function will return -1 if there is no question mark in the input, so we check the opposite
Adding a question mark should now be recognized that we will be doing the crossword helper
We will parse every letter of the input.
If it is a question mark, then we skip to the next letter. If not a question mark, then we confirm the letter matches the word's letter at the same index.
For now, we will only be checking if the length of the input and word is the same.
Add this code at the bottom of index.js:
The blacked out code is checking:
If the letter of the input and the letter of the word at the same index is NOT equal to each other, Then return false.
Add this to the bottom of index.js:
This is very similar to how we displayed the anagrams, so look at that code if you need help on the challenge.
This code should be inside the checkInput function:
We should now have all solutions appearing on the screen!
Here's an example that will display all four lettered words:
Hint: What is the string to make a new line tag for HTML?
And we are now done with the lesson!
Created 6 months ago
Teach coding to your students with MVCode Teach
MVCode offers an integrated product designed to teach coding to students.
Learn more about MVCode Teach