2017-05-08 1 views
0

Ich habe diesen Code, an dem ich arbeite, aber die Schaltfläche Berechnen funktioniert nicht, egal was ich mache. Ich möchte die Kosten pro Quadratzoll mit der PizzaSize und PizzaCost finden. Wie kann ich den Berechnungsknopf berechnen lassen?Wie funktioniert das Berechnen der Schaltfläche?

<!DOCTYPE html> 
<html lang='en'> 
<head> 
<meta charset='utf-8' > 
<title> Pizza Calculator </title> 
<script src="pizzaCalc.js"> 
</script> 
</head> 
<body> 
<h1>Pizza Calculator</h1> 
<p> 
<label for="priceBox">Cost: </label><input type="text" id="priceBox" size="5"/></p> 
<p> 
    <label for="sizeBox">Diameter :</label><input type="text" id="sizeBox"  
    size="5"/> 
</p> 
<input type="button" id="cpsi" value="Cost PSI" onclick="calculate(cpsi)"> 

</body> 
</html> 

"use strict" 
function pizzaCalc() { 
    var size = document.getElementById ("sizeBox").value; 
    size = parseFloat (size); 
    var price = document.getElementById("priceBox").value; 
    price = parceFloat (price); 
    var costPerSquareInch = price/(3.14 * (size/2)^2) 
    alert('Pizza value :' +costPerSquareInch); 
    document.getElementById("cpsi").value = costPerSquareInch; 
} 
+4

wo ist der Code für 'pizzaCalc.js'? –

+0

show js code wenn du Hilfe brauchst ansonsten theres keine Möglichkeit wir können dir helfen –

+0

Ich sehe keinen Code. Es gibt nur HTML in der Frage. –

Antwort

0

<!DOCTYPE html> 
 
<html lang='en'> 
 
<head> 
 
<meta charset='utf-8' > 
 
<title> Pizza Calculator </title> 
 
<script src="pizzaCalc.js"> 
 
</script> 
 
</head> 
 
<body> 
 
<h1>Pizza Calculator</h1> 
 
<p> 
 
<label for="priceBox">Cost: </label><input type="text" id="priceBox" value="5"/></p> 
 
<p> 
 
    <label for="sizeBox">Diameter :</label><input type="text" id="sizeBox" value="5"/> 
 
</p> 
 
<input type="button" id="cpsi" value="Cost PSI" onclick="pizzaCalc()"> 
 
    <script type="text/javascript"> 
 
    "use strict" 
 
    function pizzaCalc() { 
 
    var size = document.getElementById ("sizeBox").value; 
 
    size = parseFloat (size); 
 
    var price = document.getElementById("priceBox").value; 
 
    price = parseFloat (price); 
 
    var costPerSquareInch = price/(3.14 * (size/2)^2) 
 
    alert('Pizza value :' +costPerSquareInch); 
 
    document.getElementById("cpsi").value = costPerSquareInch; 
 
    } 
 
    </script> 
 
</body> 
 
</html>

Es scheint, dass

<input type="button" id="cpsi" value="Cost PSI" onclick="calculate(cpsi)"> 

sollte

<input type="button" id="cpsi" value="Cost PSI" onclick="pizzaCalc()"> 

auch

sein ich Größe gehe davon aus sollte Wert auf den Eingabe-Tags sein.

Verwandte Themen