+ 1
Prompt command in Functions
Can I use a Prompt command to define the argument of a function? For example is there anything wrong in a part of code like this one? <button onclick="toCelsius()">From Fahrenheit To Celsius</button> <script> function toCelsius(Fahreneit){ return (5/9)*(Fahreneit-32); document.write("The temperature is " + toCelsius(prompt("Enter Fahrenheit value")) + "° Celsius"); } </script>
2 ответов
+ 1
That won't work as you can't get past the return. This will:
<button onclick="toCelsius()">From Fahrenheit To Celsius</button>
<script>
function toCelsius() {
function convert(Fahreneit){
return (5/9)*(Fahreneit-32);
}
document.write("The temperature is " + convert(prompt("Enter Fahrenheit value")) + "° Celsius");
}
+ 1
Thanks!!