Please help to fix my jscript code for my modulus form validation of credit card number. when i key in the valid credit number the form validation will pass but if not it will refer to my documentbyelementid which is invalidcard_error.   const checkingFactor = "432765432";          //to store the credit card number         let creditCardNum = "";          //Loop till we get the valid 10 digit long credit card number         while(creditCardNum.length != 10){              //If the credit card length is not 10 then ask the user for the credit card number again             creditCardNum = prompt("Please enter your credit card number : ", "1234567890");                         //Check if the credit card number is 10 digit long or not             if(creditCardNum.length != 10){                 alert("Invalid credit card number should be 10 digits long.");                 continue;             }                         //Check if the credit card contains only numbers             if(isNaN(creditCardNum)){                 alert("Invalid credit card number. Should only contain digits");                 continue;             }          }          //TO store the sum of the credit card digits         let cardDigitSum = 0;          //Once we get the valid number from the above prompt Get the Multiply factor         for(let i = 0 ; i< creditCardNum.length-1 ; i++){              //Add the sum in the card digit sum             cardDigitSum += ( parseInt(creditCardNum[i]) * parseInt(checkingFactor[i]) );             console.log(cardDigitSum);         }          //Get the checkdigit . Checkdigit = 11 - (creditDigitSum % 11)         let checkDigit = 11 - (cardDigitSum % 11);          console.log(creditCardNum[creditCardNum.length-1]);         //Compare the check digit with the last digit of the credit card number         if(checkDigit == parseInt(creditCardNum[creditCardNum.length-1])){             alert("The number is the correct credit card number.")         }else{             alert("The number is invalid credit card number.");         }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please help to fix my jscript code for my modulus form validation of credit card number.

when i key in the valid credit number the form validation will pass but if not it will refer to my documentbyelementid which is invalidcard_error.

 

const checkingFactor = "432765432";

 

       //to store the credit card number
        let creditCardNum = "";

 

       //Loop till we get the valid 10 digit long credit card number
        while(creditCardNum.length != 10){

 

           //If the credit card length is not 10 then ask the user for the credit card number again
            creditCardNum = prompt("Please enter your credit card number : ", "1234567890");
           
            //Check if the credit card number is 10 digit long or not
            if(creditCardNum.length != 10){
                alert("Invalid credit card number should be 10 digits long.");
                continue;
            }
           
            //Check if the credit card contains only numbers
            if(isNaN(creditCardNum)){
                alert("Invalid credit card number. Should only contain digits");
                continue;
            }

 

       }

 

       //TO store the sum of the credit card digits
        let cardDigitSum = 0;

 

       //Once we get the valid number from the above prompt Get the Multiply factor
        for(let i = 0 ; i< creditCardNum.length-1 ; i++){

 

           //Add the sum in the card digit sum
            cardDigitSum += ( parseInt(creditCardNum[i]) * parseInt(checkingFactor[i]) );
            console.log(cardDigitSum);
        }

 

       //Get the checkdigit . Checkdigit = 11 - (creditDigitSum % 11)
        let checkDigit = 11 - (cardDigitSum % 11);

 

       console.log(creditCardNum[creditCardNum.length-1]);
        //Compare the check digit with the last digit of the credit card number
        if(checkDigit == parseInt(creditCardNum[creditCardNum.length-1])){
            alert("The number is the correct credit card number.")
        }else{
            alert("The number is invalid credit card number.");
        }

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
Accessibility feature of Form
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education