if you have a word like “almostomla”, do you know if it is a palindrome or not?
I did this exercise a few days back. This was how I went about it.
-
Think of the objective (create a palindrome, what is a palindrome? It is something that can be mirrored from both ends. This would be something that a function handles so before that, gather an overview of the code’s structure.
-
Comment/document the steps. For example:
2a) Reference all elements for javascript.
2b) Button event listener.
2c) A function that checks if palindrome (to be solved).
2d) Print result with innerText/textConent.
Then I looked at what common patterns can be discerned from the examples given. For example, did lower case or symbols matter? (I made a mistake and misinterpreted symbols (:/) as something to be removed, it wasn’t necessary but will pass the test’s criteria.)
-
Make console.logs of every button and empty functions to ensure they worked.
-
Back to the palindrome. How would a function be able check for characters/letters of it’s start and end point? For example, MOONOOM.
How would M, the first letter, be checked against the last letter to see if it’s equal?
Then I thought of what had been taught that may help. (array indexes, regex matching) From here, looked up what methods of the above could be used on MDN/W33. For example, .length, loop types. This step was used in the following test too, I wasn’t certain of how maps and arrays worked until looking it up and experimenting with many states.
I do think the lesson “Learn Regular Expression” (6 chapters after Palindrome) would help. You might find something there useful.