-
La mia calcolatrice
Codice HTML:
<html>
<head>
<script>
var segno;
var x;
var y;
function oper(op){
x=parseFloat(document.getElementById("dato1").value);
document.getElementById("dato1").value="";
segno=op;
}
function risultato(){
var z;
y=parseFloat(document.getElementById("dato1").value);
if (segno==='+') z=x+y;
if (segno==='-') z=x-y;
if (segno==='*') z=x*y;
if (segno==='/') z=x/y;
if (segno==='log') z= Math.log(x);
if (segno==='v') z=Math.sqrt(x);
if (segno==='%') z=x/100;
if (segno==='x?') z=Math.pow(x,y);
document.getElementById("dato1").value=z.toString();
}
function aggiungi(cifra){
document.getElementById("dato1").value=document.getElementById("dato1").value+cifra;
}
function canc(c){
document.getElementById("dato1").value=document.getElementById("dato1").value="";
x="";
y="";
}
</script>
</head>
<body background="https://www.costieraamalfitana.com/wp-content/uploads/2016/07/banner-atrani.jpg">
<img
<h1 align=center style="color:red">CALCOLATRICE DI MARIO CITARELLA</h1>
<center>
<table borderColor=red border="2" style="background:red">
<tr><input style="background:gray" type="text" id="dato1" ></tr>
<tr><td><input type="button" id="to1" name="to1" value="1" onClick=aggiungi(this.value)>
<td><input type="button" id="to2" name="to2" value="2" onClick=aggiungi(this.value)>
<td><input type="button" id="to3" name="to3" value="3" onClick=aggiungi(this.value)>
<td><input type="button" id="operatore+" value="+" onClick=oper(this.value)>
<td><input type="button" id="operatorelog" value="log" onClick=oper(this.value)>
</tr><br><br>
<tr><td><input type="button" id="to4" name="to4" value="4" onClick=aggiungi(this.value)>
<td><input type="button" id="to5" name="to5" value="5" onClick=aggiungi(this.value)>
<td><input type="button" id="to6" name="to6" value="6" onClick=aggiungi(this.value)>
<td><input type="button" id="operatore-" value="-" onClick=oper(this.value)>
<td><input type="button" id="operatorev" value="v" onClick=oper(this.value)>
</tr>
<tr><td><input type="button" id="to7" name="to7" value="7" onClick=aggiungi(this.value)>
<td><input type="button" id="to8" name="to8" value="8" onClick=aggiungi(this.value)>
<td><input type="button" id="to9" name="to9" value="9" onClick=aggiungi(this.value)>
<td><input type="button" id="operatore*" value="*" onClick=oper(this.value)>
<td><input type="button" id="operatore%" value="%" onClick=oper(this.value)>
<td><input type="button" id="operatorex?" value="x?" onClick=oper(this.value)>
</tr>
<tr><td><input type="button" id="toC" name="toC" value="C" onClick=canc(this.value)>
<td><input type="button" id="to0" name="to0" value="0" onClick=aggiungi(this.value)>
<td><input type="button" id="to," name="to," value="." onClick=aggiungi(this.value)>
<td><input type="button" id="operatore/" value="/" onClick=oper(this.value)>
<td><input type="button" value="=" onClick=risultato(segno)></tr>
</table>
</center>
</body>
</html>