Skip to main content
Write a JavaScript program to find square and cube of number using function.
CODING:
<html>
<head>
<title>
</title>
<script>
function squ(){
var a;
a=Number(document.getElementById("no").value);

document.getElementById("ans1").value=a*a;
}

function cub(){
var c,b;
b=Number(document.getElementById("no").value);
c=b*b*b;
document.getElementById("ans2").value=c;
}
</script>
</head>
<body>
Enter The Value:<input type="text"  id="no"><br><br>
<input type="button" value="SQUARE"  onclick="squ()">
<input type="text"   id="ans1">
<br><br><input type="button" value="CUBE"  onclick="cub()">
<input type="text"   id="ans2">
</body>
</html>

Comments