Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-26-2012, 03:03 AM   PM User | #1
msNewbie
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
msNewbie is an unknown quantity at this point
.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..
msNewbie is offline   Reply With Quote
Old 09-26-2012, 03:08 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
msNewbie (09-26-2012)
Old 09-26-2012, 03:19 AM   PM User | #3
msNewbie
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
msNewbie is an unknown quantity at this point
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.
msNewbie is offline   Reply With Quote
Old 09-26-2012, 03:28 AM   PM User | #4
msNewbie
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
msNewbie is an unknown quantity at this point
I don't know what I just did but it works.
Thanks for your patience and quick reply!
msNewbie is offline   Reply With Quote
Old 09-26-2012, 03:38 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:41 AM.


Advertisement
Log in to turn off these ads.