Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array/Validation

    --Got it.
    Last edited by Saakashvili; 12-12-2009 at 07:49 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,309
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Homework?

    Do it like this:-

    Code:
    <script type = "text/javascript">
    function GetExamGrade ()  {
    var ex;
    var examReturn = 0;
    examNumber = parseInt(prompt("Number of exams?",""));
    examGrade = new Array(examNumber);
    for (var i = 1; i <= examNumber; i++) {
    ex= parseInt(prompt("Enter exam score " + (i) +"! ",""));
    examGrade[i] = ex;
    if ((isNaN(ex)) || (ex < 0) || (ex > 105)) {
    alert("Your number must be at least 0 and not more than 105!");
    i --;
    }
    
    examReturn += (examGrade[i] / i);
    }
    
    return examReturn;
    }
    
    </script>

    Quizmaster: La Stampa and La Repubblica are newspapers published in which European country?
    Contestant: Mexico

  • #3
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Homework?

    Do it like this:-

    Code:
    <script type = "text/javascript">
    function GetExamGrade ()  {
    var ex;
    var examReturn = 0;
    examNumber = parseInt(prompt("Number of exams?",""));
    examGrade = new Array(examNumber);
    for (var i = 1; i <= examNumber; i++) {
    ex= parseInt(prompt("Enter exam score " + (i) +"! ",""));
    examGrade[i] = ex;
    if ((isNaN(ex)) || (ex < 0) || (ex > 105)) {
    alert("Your number must be at least 0 and not more than 105!");
    i --;
    }
    
    examReturn += (examGrade[i] / i);
    }
    
    return examReturn;
    }
    
    </script>

    Quizmaster: La Stampa and La Repubblica are newspapers published in which European country?
    Contestant: Mexico
    It's more of a side-project I'm doing for an internship.

    I'm required to use the the GetValidInput function for all input verification.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •