# Bhaj's Word Checker Explainer

Word Checker 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 checks if a word could potentially fit as a crossword answer.

This function will take a word, for example, `'cat'`, and a space, for example, `'-a-'`, and will return `true` if the word can fit in the space, and `false` if it cannot.

First, we know that if the word and the space are different lengths, the word will not fit. Therefore, add an if statement that compares the lengths, and returns `false` if they are not equal. This will take care of any words that are too long or too short.

Next, we need to check the words that are the right length. Add a classic for loop to iterate through the space.

Inside the for loop, add an if statement. This if statement should check 2 things. 1st, we want to check the characters in the space that are not `'-'`.

2nd, we want to check if the characters that are not `'-'` are not equal to the character in the same position in the word.

It will look like this:

``````    for (let i = 0; i < space.length; i++) {
if (space[i] !== '-' && space[i] !== word[i]) {
return false;
}
}
``````

Finally, at the end of the function, `return true`. The function will only execute this line of code if the for loop finishes iterating without returning `false` early.

Sample code solution:

``````import { randomWord } from 'cross.words';

function check(space, word) {
if (space.length !== word.length) {
return false;
}
for (let i = 0; i < space.length; i++) {
if (space[i] !== '-' && space[i] !== word[i]) {
return false;
}
}
return true;
}

console.log('-a-t');
console.log(randomWord);
console.log(check('-a-t', randomWord));

``````

Javascript Concepts: Functions, If Statements, For Loops, Strings, Bracket Notation, Indexing, Return Statements
Additional Code (hidden code that runs before the puzzle’s code):

``````const _words = ['bait','cart','cast','daft','dart','east','fact','fast','gait','gast','halt','last','malt','mast','pact','pant','part','past','raft','rant','salt','tact','tart','vast','waft','wait','want','wart','watt','cats','bats','rats','bate','bath','bats','cats','data','date','eats','fate','fats','gate','hats','late','mate','math','oath','oats','rate','rats','baits','darts','attach','attack','attain','strata','tartan','tartar','tatars','aeronautics','alterations','astronautic','automations','devastation','evacuations','evaluations','salutations','situational','accusation','aeronautic','agitations','alteration','automating','automation','gelatinous','hesitation','infatuated','passionate','poinsettia','quotations','restaurant','valuations','adult','basil','bones','doses','early','heads'];

defineModule(
'cross.words',
{
randomSpace: pickRandom(_words).split('').map(i=>pickRandom([i,'-'])).join(''),
randomWord: pickRandom(_words)
}
);
``````

Hey I have been looking on all the Possibilities for this Puzzle and I really do need some Help Please and Thank You