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.