Okay, there are two problems in this project. One of them is that it requires the use of a regex like this: /[a-z0-9]+/ig
. However, the only previous course before this project where regex was taught was Learn Form Validation by Building a Calorie Counter from steps 19 to 33. The problem is that they didn’t teach how to match alphabet characters from a to z; they only taught how to match numeric characters from 0 to 9. So, the only way to do it was to try with imagination until you solved it by imitating the way to match numeric characters, doing something like this: /[abcdefghijklmnopqrstuvwxyz0-9]/
or searching online.
There is also another problem, and that is that they didn’t teach how to not match spacing. A beginner might have done this: /[abcdefghijklmnopqrstuvwxyz 0-9]/
, which will match a whitespace.
And the last problem is that they didn’t teach in previous courses how to convert text to the same case (uppercase to lowercase)(toLowerCase() method) . So, a beginner wouldn’t know what to do unless they rack their brains until they achieve something like this:
const upToLow = {
'A': 'a', 'B': 'b', 'C': 'c', 'D': 'd', 'E': 'e', 'F': 'f', 'G': 'g', 'H': 'h', 'I': 'i', 'J': 'j', 'K': 'k', 'L': 'l', 'M':'m', 'N': 'n', 'O': 'o', 'P': 'p', 'Q': 'q', 'R': 'r', 'S':'s', 'T': 't', 'U': 'u', 'V': 'v', 'W': 'w', 'X': 'x', 'Y': 'y', 'Z': 'z'
};
const text1 = "HELLO WORLD";
let lowText = '';
for (let i = 0; i < text1.length; i++) {
const char = text1[i];
lowText += upToLow[char] || char;
}
I have a good foundation in JavaScript, so I always knew what to do. However, I am criticizing this to help beginners.
Please note that English is not my first language. I want to provide constructive criticism, and I apologize if anything sounds offensive.