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 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts

    .html shows up but .js does not

    I have been doing good in class so far but ran into a problem today.
    Believe it or not this is right from the book:
    'Programming with JavaScript' by Dionisio
    Here is the .html page:
    Code:
    <!doctype html>
    <html>
    	<head>
    		<meta charset="UTF-8"/>
    		<title>JavaScript Temperature Converter</title>
    	</head>
    	<body>
    		<h1>Temperature Conversion</h1>
    		<p>
    			<input type="text"   id="temperature" />
    			<input type="button" id="f_to_c" value="F to C" />
    			<input type="button" id="c_to_f" value="C to F" />
    		</p>
    		<p id="result"></p>
    		<script src="temperature.js"></script>
    	</body>
    </html>
    Next is the .js code
    Code:
    var report = function (celsius, fahrenheit) {
    	document.getElementById("result").innerHTML = 
    		celsius + "° = " + fahrenheit + "°";
    		};
    	document.getElementById("f_to_c").onclick = function () {
    		var fahrenheit = document.getElementById("temperature").value;
    		report((f - 32) / 1.8, f);
    	};
    	
    	document.getElementById("c_to_f").onclick = function () {
    		var celsius = document.getElementById("temperature").value;
    		report(c,1.8 * c + 32);
    	};
    Like I said it is directly from the book and I had 3 other people see if I missed anything or made any kind of mistake.
    Can someone please try to run this and see what I am talking about? If you think you have the answer can you please test first before posting.
    Last edited by msNewbie; 09-26-2012 at 03:21 AM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    There is a } missing after the third line to end the first of the three functions.
    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.

  • Users who have thanked felgall for this post:

    msNewbie (09-26-2012)

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    There is a } missing after the third line to end the first of the three functions.
    My bad! I just forgot to copy that from the file.
    Thanks for pointing that out I will try to edit above code.

  • #4
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I don't know what I just did but it works.
    Thanks for your patience and quick reply!

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    There were other things wrong with the code as shown.

    If it works, you changes a lot more than what Felgall showed you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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