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
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple javascript program loading blank page

    This is a very basic script I have to do for class, but it is loading a blank screen. I've gone over it many times, but I can't find what is wrong with it.

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    	<meta charset="UTF-8">
    	<title>Problem 2</title>
    </head>
    <body>
    <script type = "text/javascript">
    	var name = window.prompt("Enter your name", "");		
    	var major = window.prompt("Enter your major ie: CI", "");		
    	var credits = parseInt(window.prompt("Enter your number of credits", 0);
    	var gpa = parseFloat(window.prompt("Enter your GPA ie: 3.2", 0.0));
    
    	if ( (major == "CI") && (credits > 45 || gpa > 2.5) )
    	{
    		document.write(name + ", you are entering your last semester.");
    	}
    </script>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Let me guess: The console of your developer tools tells you that there is a syntax error in script line 3. I propose you count the number of opening and closing parentheses in this line.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,472
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Quote Originally Posted by Dankaru View Post
    This is a very basic script I have to do for class,
    Presumably it is a history class. JavaScript like that is as dead as Netscape 4. Current JavaScript looks completely different and does not use either prompt or document.write.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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