1Create a webpage that when visited displays a propt asking
1.Create a webpage that, when visited, displays a propt asking for the user\'s name. If they don\'t input a name, keep asking for one. I a second prompt, ask for the user\'s age. If they don\'t input a valid value (we\'ll say valid ages are 0 -150 inclusive), keep asking for one. Finally, display and alert with the text, \"Hello [NAME]. You are [AGE] years old!\" with the correct values filled in.
2. On this page, you are to create a very basic caluclator. This should consist of two textboxes for input values, and somewhere to display the result on the page. There should also be buttons for the following mathematical operations: +,-,*,/,^(exponent), and square root. The calculator should work like this: user enters two values in to the text boxes, user clicks an operator, then the result is displayed somewhere on the page. Also, I have to add somewhere on the page to display the \"history\" of the calculator (previously done operations with values, operator, and result).
JAVASCRIPT
Solution
<!DOCTYPE html>
<html>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick=\"myFunction()\">Try it</button>
<p id=\"demo\"></p>
<script>
function myFunction() {
var person = prompt(\"Please enter your name\", \" \");
if (person != null) {
document.getElementById(\"demo\").innerHTML =\"Hello \" + person + \"
}
else
{
<button onclick=\"myFunction()\">Try it</button>
<script>
function myFunction() {
alert(\"Hello please enter your name!\");
}
</script>
}
</body>
</html>
2)<html>
<head>
<title>Arithmetic operations</title>
</head>
<script type=\"text/javascript\">
function Addition()
{
var x,y,z;
x=parseFloat(calc.value1.value);
y=parseFloat(calc.value2.value);
z=x+y;
alert(\"The Addition result is\"+(z));
calc.value3.value=z
}
function Subtraction()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=x-y;
alert(\"The subtraction result is \"+z);
calc.value3.value=z
}
function Multiplication()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=x*y;
alert(\"The Multiplication result is \"+z);
calc.value3.value=z
}
function Division()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=x/y;
alert(\"The subtraction result is \"+z);
calc.value3.value=z
}
function Squareroot()
{
var x,z;
x=parseFloat(calc.value1.value);
z=Math.sqrt(x);
alert(\"The Squareroot is\"+(z));
calc.value3.value=z
}
function Power()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=Math.pow(x,y);
alert(\"The exponential result is \"+z);
calc.value3.value=z
}
</script>
</head>
<body>
<form name=\"calc\">
<h1>Online Calculator</h1>
Enter first Numeric Value : <input type=\"number\" id=\"value1\"> </br>
Enter Second Numeric Value : <input type=\"number\" id=\"value2\"> </br>
</br>
Result of the Arithmetic operation is : <output type=\"number\" id=\"value3\"> </output></br>
<input type=\"button\" Value=\"Addition\" onClick=\"Addition()\"> </br>
<input type=\"button\" Value=\"Subtraction\" onClick=Subtraction()></br>
<input type=\"button\" Value=\"Multiplication\" onClick=Multiplication()></br>
<input type=\"button\" Value=\"Division\" onClick=Division()></br>
<input type=\"button\" Value=\"Squareroot\" onClick=Squareroot()></br>
<input type=\"button\" Value=\"Power\" onClick=Power()></br>
</form>
</body>
</html>



