Word Play 2

Information
Step 1
Anagram is a word created by rearranging the letters of another word
Anagram listen silent
Planning
Step 2
In this lesson, we will be finding all possible anagrams for a certain input

It will also show anagrams that have less amount of letters than the input such as this example:

1
Information
Step 3
The way we will check if two words are anagrams is by process of elimination

We go through each letter for a potential anagram word and make sure it can cross out a letter from the input that isn't already crossed out.

1
Information
Step 4
To find the index of a certain item in an array we can use the indexOf function

Here's an example of the function indexOf returning the number 2 to indicate the index of the letter "R" in the array:

13

If there is no index then the function will return -1, as shown in this example:

14
Challenge
Step 5
Create a function that can check if a potential word is an anagram of an input word

You do NOT need to copy the green lines because they are comments and only there to help explain each line of code.

Also this code should at the bottom of index.js:

10
Check Your Work
Step 6
Save your code

To test the function add two console.log lines at the bottom of your code and check the console

12
Step 7
Create a function to check every word in the words array and add it to an array if its an anagram for a certain input

This should go inside index.js:

15
Step 8
Now let's add a line of code to test the new function

Add this line of code inside the checkInput function:

19
Check Your Work
Step 9
Try typing an input to the website and see if the anagrams appear in the console
18
Challenge
Step 10
Add some code to not include the input as an anagram

The code should be checking if the input and the potential anagram word are EQUAL to each other.

20
Check Your Work
Step 11
Save your code and test to see if the code worked
21
Planning
Step 12
Now we will display the results to the screen instead of the console
1
Information
Step 13
To add a line break to an HTML paragraph tag we need to use the "<br>" tag
24
Step 14
Add this code to display the anagrams if there is any or a message saying there is no anagrams
23
Check Your Work
Step 15
Save your code and see if the anagrams appear on the website
25
Information
Step 16
This does not look very good and causes problems when there are many anagrams such as this example:
26
Planning
Step 17
To fix it we will group the anagrams based on the number of letters in the word
27
Information
Step 18
We will need to find the shortest and longest number to know the range
28
Step 19
Let's make a function that will find the shortest and longest word in an array

Add this to index.js:

30
Step 20
Let's now go through each word and check if it is the longest word and update if so
31
Challenge
Step 21
Add code to check if there are any words less than the shortest word in order to update it
33
Step 22
To test it let's add this console.log after we display the anagrams
34
Check Your Work
Step 23
If you use the example "anagrams" then you should see this
35
Step 24
Let's make a new function that will display the anagrams all organized

Add this to index.js:

36
Step 25
Let's now use the function to display the anagrams
37
Check Your Work
Step 26
Save your code and see if it displays the categories correctly

This should appear for the "anagrams" example:

38
Challenge
Step 27
Let's now add the anagrams into their respective categories

The hidden code should be checking if the certain anagram word's length is equal to the certain length category.

40
Check Your Work
Step 28
The code should now work correctly!
27
Planning
Step 29
In the next lesson we will be adding autocomplete suggestions to help users find a certain word
41
Word Play 2 Info

Account

MVCode Clubs

Created By

Missing tiny aaronjau101

Course:

Word Play

Access Level

premium

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach