Use prompts the user to enter a GBLearn ID. You will need to use RegExp inside try & catch block to evaluate whether the id is in a proper format, if not, throw an error to display an alert message to the user in your catch block). As you know, all GBLearn IDs begin with a lowercase letter for each season (w for winter, s for summer...), followed by 7 digits. If user input is in a valid format, create a new h3 element and embed user’s input as a new text node to the h3 element, then append it to the div the container created above (in your HTML document).
I try to check if the inputted text on the required format. If you know how to fix it, I will appreciate it.
"use strict";
let button = document.getElementById("Enter_your_id");
button.addEventListener("click", EnterID, false);
function EnterID() {
let input = "";
try {
input = prompt("Enter your id");
let regex = new RegExp("/^(w|s)-[0-9]{7}");
if (input == null) {
throw new Error("The field can not be empty");
}
if (!regex.exec(input)) {
throw new Error("Incorrect format");
}
} finally {
let text = EnterID();
let output = document.querySelector("#output h3");
output.innerHTML = text;
}
}