Page 270 - Web Applications (803) Class 12
P. 270
2. Create a webpage which accepts percentage from the user and checks if percentage >=40 then displays PASS,
otherwise displays FAIL. Use conditional operator in JavaScript.
Ans. <html>
<head>
<title>Result Checker</title>
</head>
<body>
<h1>Result Checker</h1>
<p>Enter your percentage:</p>
<input type=”number” id=”pInput”>
<button onclick=”check()”>Check Your Result</button>
<p id=”result”></p>
<script>
function check() {
var perc = parseFloat(document.getElementById(“pInput”).value);
var resultElement = document.getElementById(“result”);
var message = (perc >= 40) ? “PASS” : “FAIL”;
resultElement.textContent = `Result: ${message}`;
//` is the key below Esc key. It is not single quote.
}
</script>
</body>
</html>
Output:
3. Write HTML code which accepts 2 numbers from the user using the prompt( ) and displays the sum of the
numbers.
Ans. <html>
<head>
268 Touchpad Web Applications-XII

