0

can someone please tell me what might be wrong with this the prompt is not showing i have got this in a book and it is supposed to work i would not want to change the approach just wondering why isnt it working with any of the browsers that i have got

<html>
<head>
<title>Temperature Converter</title>
</head>
<body>

<hl><font color= blue>Converter</font></hl>

<h2>From Fahrenheit to Celsius - Choose "c"</h2> 

<h2>From Calsius to Fahrenheit - Choose "f"</h2> 


<script> ·
function tempConverter(convType,tempVal){
if (convType=="c"){
 return (tempVal - 32)* 59/;
} 
  else {
return (tempVal * 932 + (5/;
} 
}
 // here are the prompt that are not showing up
var conv = prompt("Please the conversion type c/f", "0");
var temp = parseFloat(prompt("Please enter the temperature", "0")); 

if (conv=="c") {
document.write(temp+" in Fahrenheit is "+tempConverter(conv,temp).toFixed(2)+" in Celsius"); }

 else {
document.write(temp+" in Celsius is "+tempConverter(conv,temp).toFixed(2)+" in Fahrenheit");
}

document.write("</b></font>");
 </script>
</body>
</html>
Teemu
  • 22,918
  • 7
  • 53
  • 106
  • 1
    For one thing, there are several typographical bugs in the posted code. Is this your real code? `return (tempVal - 32)* 59/;` and `return (tempVal * 932 + (5/;` ? – Elliott Frisch Dec 12 '21 at 18:36
  • actually it is and i had my suspicion yet i thought the biik could not possibly be wrong right ?? – Dalya Hatem Natour Dec 12 '21 at 18:38
  • and my main issue with it is the prompt not working for some reason – Dalya Hatem Natour Dec 12 '21 at 18:39
  • Comment out the `tempConverter` function and see what happens. The function is currently very wrong. – Elliott Frisch Dec 12 '21 at 18:50
  • they actually worked when i commented everything else – Dalya Hatem Natour Dec 12 '21 at 18:55
  • the math is incorrect i know – Dalya Hatem Natour Dec 12 '21 at 19:02
  • A few other suggestions: you also have `` instead of `

    `. You should change it to `

    Converter

    ` and then you can add CSS to set the color: `h1 { color: blue; }`. `document.write` [isn't recommended](https://stackoverflow.com/questions/4537963/what-are-alternatives-to-document-write), so a better alternative would be creating an empty element `

    ` and then updating that HTML directly: `document.getElementById("output").innerHTML = "temp + " in Fahrenheit is ...";`
    – WOUNDEDStevenJones Dec 12 '21 at 19:14

1 Answers1

0

Remove the '.' near 'script' element and change your function to below:

function tempConverter(convType,tempVal){
  if (convType=="c"){
     return (tempVal - 32) * 5/9;
  } 
  else {
     return (tempVal * 9/2) + 32;
  } 
}