Satyam_2020CA081Web 9)
Satyam_2020CA081Web 9)
input[type="button"] {
background-color: rgb(196, 196, 196);
color: black;
border: solid black 2px;
width: 100%;
}
<script>
/* Creating function in HTML for backspace operation */
function backspace(calc) {
size = calc.display.value.length;
calc.display.value = calc.display.value.substring(0, size - 1);
}
<body>
<div class="title">Simple Calculator</div>
<form name="calc">
<table id="calc" border="2">
<tr>
<td colspan="5">
<input
id="btn"
name="display"
onkeypress="return event.charCode >= 48 && event.charCode <= 57"
type="text"
/>
</td>
</tr>
<tr>
<td>
<input
id="btn"
type="button"
value="1"
OnClick="calc.display.value+='1'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="2"
OnClick="calc.display.value+='2'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="3"
OnClick="calc.display.value+='3'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="C"
OnClick="calc.display.value=''"
/>
</td>
<td>
<input
id="btn"
type="button"
value="<-"
OnClick="backspace(this.form)"
/>
</td>
<td>
<input
id="btn"
type="button"
value="="
OnClick="calculate(this.form)"
/>
</td>
</tr>
<tr>
<td>
<input
id="btn"
type="button"
value="4"
OnClick="calc.display.value+='4'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="5"
OnClick="calc.display.value+='5'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="6"
OnClick="calc.display.value+='6'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="-"
OnClick="calc.display.value='-'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="%"
OnClick="calc.display.value+='%'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="cos"
OnClick="calc.display.value='Math.cos('"
/>
</td>
</tr>
<tr>
<td>
<input
id="btn"
type="button"
value="7"
OnClick="calc.display.value+='7'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="8"
OnClick="calc.display.value+='8'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="9"
OnClick="calc.display.value+='9'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="*"
OnClick="calc.display.value+='*'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="n!"
OnClick="calc.display.value+='!'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="sin"
OnClick="calc.display.value='Math.sin('"
/>
</td>
</tr>
<tr>
<td>
<input
id="btn"
type="button"
value="."
OnClick="calc.display.value+='.'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="0"
OnClick="calc.display.value+='0'"
/>
</td>
<td>
<input
id="btn"
type="button"
value=","
OnClick="calc.display.value+=','"
/>
</td>
<td>
<input
id="btn"
type="button"
value="+"
OnClick="calc.display.value+='+'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="/"
OnClick="calc.display.value+='/'"
/>
</td>
<td>
<input
id="btn"
type="button"
value="tan"
OnClick="calc.display.value='Math.tan('"
/>
</td>
</tr>
</table>
</form>
</body>
</html>
Q2. Write A JAVAScript thAt cAlculAtes the squAres And cubes of
the numbers from 0 to 10 And outputs HTML text thAt displAys
the resulting vAlues in An HTML tAble formAt.
<!DOCTYPE HTML>
<html>
<head>
<title>Square and Cubes</title>
<style>
table,tr, td
{
border: solid black;
width: 33%;
text-align: center;
border-collapse: collapse;
background-color: rgb(255, 233, 109);
}
table { margin: auto; }
</style>
<script>
document.write( "<table><tr><th colspan='3'> NUMBERS FROM 0 TO 10 WITH THEIR
SQUARES AND CUBES </th></tr>" );
document.write( "<tr><td>Number</td><td>Square</td><td>Cube</td></tr>" );
for(var n=0; n<=10; n++)
{
document.write( "<tr><td>" + n + "</td><td>" + n*n + "</td><td>" + n*n*n
+ "</td></tr>" ) ;
}
document.write( "</table>" ) ;
</script>
</head>
</html>
O Quare and Cubes
C @ 127.0.0,1:5500/Ques2.html
i
2 4
3 9 27
6 36
Sl2
BJ 729
Q3. Write A JAVA script to prompt for user’s nAme And displAy it
on the
screen.
<!DOCTYPE html>
<html>
<head>
<title>Name Prompt</title>
</head>
<style>
* {
margin: 10px;
padding: 5px;
}
body {
background-color: rgb(166, 215, 243);
}
</style>
<body>
<p id="demo"></p>
<script>
function myFunction() {
let person = prompt("Please enter your name", "Harry Potter");
if (person != null)
{ document.getElementById("demo").innerHTML
= "Hello " + person + "! How are you
today?";
}
}
</script>
</body>
</html>
2 0 1 Z7.0.0 1. fi 0y Ot es1. ntm I
a) PArAmeter: A string
c) PArAmeter: A number
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Left Most Vowel/ Reverse Number</title>
</head>
<style>
* {
margin: 10px;
padding: 5px;
}
body {
background-color: rgb(166, 215, 243);
}
</style>
<script>
var a = prompt("Enter The Query (Number: reverse; String: leftmost vowel
pos.)"),b = parseInt(a),z=0;
if(b) {
while(b>0)
var r= b%10, z= z*10+r, b = Math.floor(b/10);
document.write("Entered Query : "+ a +"<br> Given Number In Reverse Order : "+
z);
}
else {
a = a.search(/[aeiouAEIOU]/);
document.write("The First Occurence Of Vowel is at : "+ (a+1));
}
</script>
</html>
Q5. Write A jAVA script progrAm which compute, the AVerAge
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Avg Marks</title>
</head>
<style>
* {
margin: 10px;
padding: 5px;
}
body {
background-color: rgb(196, 196, 196);
}
</style>
<body>
<div class="avg-marks">
<div>
<label for="marks"> Marks of the sutdent</label>
<input type="text" id="marks" name="marks" disabled size="50" />
</div>
<div>
<label for="avg">Average</label>
<input type="text" id="avg" name="avg" disabled size="50" />
</div>
<div>
<label for="grade"> Grade</label>
<input type="text" id="grade" name="grade" disabled size="50" />
</div>
<button onclick="avg()">Calculate Avg and Grade</button>
</div>
</body>
<script>
function avg() {
let marks = [98, 89, 87, 99, 98];
document.getElementById("marks").value = marks;
let sum = 0;
for (let i = 0; i < marks.length; i++)
{ sum += marks[i];
}
let avg = (1.0 * sum) / marks.length;
document.getElementById("avg").value = avg;
document.getElementById("grade").value = grade;
}
</script>
</html>