SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with why this is not working

    Can someone take a look at this and tell me why this does not work. It does not make it all the way thru the function.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>

    <script type="text/javascript">
    function cabFair(start, end, time){
    var base = 0;
    if (start = 1){
    if (end = 1){
    base = 5;
    }if (end = 2) {
    base = 7;
    }base = 8;
    }if (start = 2){
    if (end = 1){
    base = 7;
    }if (end = 2) {
    base = 5;
    }base = 9;
    }if (end = 1){
    base = 8;
    }if (end = 2) {
    base = 9;
    }base = 5;
    //return(base);

    if (time > 20){
    time1 = (time - 20);
    time2 = (time1 * (.3));
    finalTime = (time2 + 10);
    }if (time > 10 && time <= 20){
    time1 = (time - 10);
    time2 = (time1 * (.4));
    finalTime = (time2 + 6);
    }if (time >4 && time <= 10){
    time1 = (time - 4);
    time2 = (time1 * (.5));
    finalTime = (time2 + 3);
    }finalTime = (time * .75);
    var fare = finalTime + base;
    return fare
    }

    </script>
    </head>
    <body>
    <script type="text/javascript">
    //Ask user for input
    var start = parseInt(prompt("Enter the Starting Point", "1"));
    var end = parseInt(prompt("Enter the Ending Point", "2"));
    var time = parseInt(prompt("Enter the Total Time", "4"));
    //output for information
    document.writeln(cabFair(start, end, time)
    + " Is the Total Fare.");

    </script>
    </body>
    </html>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I just tested it and it works fine for me, what is happening when you try to run it?


Bookmarks

Posting Permissions

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