0

else is not working. If the inputs are all empty, it should fall to else statement.

let firstName = (prompt("First Name"));
let lastName = (prompt("Last Name"));
let emailAdd = (prompt("Email Address"));
let password = (prompt("Password"));
let confirmPassword = (prompt("Confirm Password"));

function getInfo(firstName, lastName, emailAdd, password, confirmPassword){

    if (firstName.length !== 0 && lastName.length !== 0 && emailAdd.length !== 0 && password.length !== 0 && password.length >= 8 && confirmPassword.length !== 0 && password === confirmPassword){

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")

    } else if (firstName === ""){
            console.log("First name is not entered.");
            firstName = (prompt("First Name"));

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")

    } else if (lastName === ""){
            console.log("Last name is not entered.");
            lastName = (prompt("Last Name"));

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")

    } else if (emailAdd === ""){
            console.log("Email address is not entered.");
            emailAdd = (prompt("Email Address"));

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")

    } else if (password === ""){
            console.log("Password not provided. Confirmation invalid.");
            password = (prompt("Password"));
            //confirmPassword = (prompt("Confirm Password"));

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")

    } else if (confirmPassword === ""){
            console.log("Password not confirmed.");
            confirmPassword = (prompt("Confirm Password"));

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")

    } else if (confirmPassword !== password){
            console.log("Password not matched.");
            password = (prompt("Password"));
            confirmPassword = (prompt("Confirm Password"));

            console.log("First Name: " + firstName);
            console.log("Last Name: " + lastName);
            console.log("Email Address: " + emailAdd);
            console.log("Password: " + password);
            console.log("Confirm Password: " + confirmPassword);
            console.log("Information accepted.")
    } else {
            console.log("Please fill in your information.");
            return false;
    }
}

getInfo(firstName, lastName, emailAdd, password, confirmPassword);

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jclarete
  • 11
  • 1
  • `function getInfo(firstName, lastName` etc means that the identifiers `firstName`, `lastName`, etc, are *arguments* passed to the function, not the outer variables. But you never passed any arguments. – CertainPerformance Apr 29 '21 at 16:23
  • The last line should include all parameters as the arguments to the function call. – luk2302 Apr 29 '21 at 16:23
  • @CertainPerformance How can I pass to the function the data input thru prompt()? Should I put the prompt inside the function? Can you share how to do that? – jclarete Apr 29 '21 at 16:25
  • @luk2302 yes, I am not sure how the arguments should be written if based on my code above where prompts take place before fucntion. But if there's a correction, I need help. – jclarete Apr 29 '21 at 16:26
  • 2
    Also, you may want to consider validating the input as soon as you receive it so that you an re-prompt for valid input right away and then only call the function after the input has been validated. With all the questions you are asking, I'd hate to answer 5 questions only for you to tell me that my first answer wasn't valid. – Scott Marcus Apr 29 '21 at 16:26
  • `getInfo(firstName, lastName, emailAdd, password, confirmPassword);` – luk2302 Apr 29 '21 at 16:27
  • Well, think about it. You've already got `getInfo()`, so it appears that you know how to call your function. And, you've got the responses from your `prompt`s stored in variables, so it appears you know where the data is. If the function requires arguments to be passed to it and arguments go inside of `()`, what do you think you might do when you call the function? – Scott Marcus Apr 29 '21 at 16:29
  • @ScottMarcus Thank you. I'm just new to programming and trying to understand the language. – jclarete Apr 29 '21 at 16:34
  • There's no better way to learn than to try. – Scott Marcus Apr 29 '21 at 16:35
  • question and code updated. – jclarete Apr 29 '21 at 17:26

0 Answers0