View Full Version : .html shows up but .js does not

09-26-2012, 04:03 AM
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:

<!doctype html>
<meta charset="UTF-8"/>
<title>JavaScript Temperature Converter</title>
<h1>Temperature Conversion</h1>
<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 id="result"></p>
<script src="temperature.js"></script>

Next is the .js 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.

09-26-2012, 04:08 AM
There is a } missing after the third line to end the first of the three functions.

09-26-2012, 04:19 AM
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.

09-26-2012, 04:28 AM
I don't know what I just did but it works.
Thanks for your patience and quick reply!

Old Pedant
09-26-2012, 04:38 AM
There were other things wrong with the code as shown.

If it works, you changes a lot more than what Felgall showed you.