I'm currently working on a script that will be used by the secretaries in our school district to generate unique codes for new students or hires. The code will consist of an 8-digit output, a randomly generated 6-digit number, and the user's initials at the end. This unique code will trigger automatic account creation in our systems. While we have the account creation process set up and working smoothly, we're facing challenges with generating the unique code. I've omitted the random number generation part of the script since my main obstacle lies in prompting for the user's name and extracting their initials.
function ID() {
var userName = prompt("Please enter your name", "<User Name>");
}
function getInitials(name) {
let initials = "";
let waitingForSpace = false;
for (var i = 0; i < name.length; i++) {
if (!waitingForSpace) {
initials += name[i];
waitingForSpace = true;
}
if (name[i] === " ") {
waitingForSpace = false;
}
}
return initials;
}
console.log(getInitials(userName));
I expect to receive a prompt for the User Name, which will be stored as userName. This variable is then passed to the getInitials function. However, when attempting to run Node Initials.js, I encounter the following error message...
ReferenceError: userName is not defined
at Object. (/Users/dross/Documents/UserID/Initials.js:22:25)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)