Std XI I.T || Skill Set 3 – JavaScript || SOP1
SOP1: Create JavaScript program for the following
using appropriate variables, JavaScript inbuilt functions and control
structures.
·
- To accept integer and display the result by multiplying it with 3.
<!DOCTYPE
html>
<html>
<head>
<title>sop1</title>
</head>
<body>
<h1>To accept
integer and display the result by multiplying it with 3</h1>
<script language=javascript>
var num,ans
num=prompt("Enter
a number")
ans=num*3
document.write("Answer
= "+ans)
</script>
</body>
</html>
Type the code in notepad application and save the code as usual in a folder.
Provide suitable filename for example sopjs1a.html.
In these examples we are embedding JavaScript codes in HTML hence
we provide .html extensions to the filenames.
To see the output as per academic specifications use Internet Explorer
web browser.
Click on Allow Blocked contents button as demonstrated through picture to provide input
during runtime and see the final result.
Type the code in notepad application and save the code as usual in a folder.
Provide suitable filename for example sopjs1a.html.
In these examples we are embedding JavaScript codes in HTML hence
we provide .html extensions to the filenames.
To see the output as per academic specifications use Internet Explorer
web browser.
Click on Allow Blocked contents button as demonstrated through picture to provide input
during runtime and see the final result.
- To accept two integers
and display larger number of them.
<!DOCTYPE
html>
<html>
<head>
<title>sop1</title>
</head>
<body>
<h1> To accept two integers and display larger number of them </h1>
<script language=javascript>
var n1,n2
n1=prompt("Enter first number","type
here")
n2=prompt("Enter second number","type
here")
if(n1>n2)
document.write(n1+ " is the greater number")
else
document.write(n2+ " is the greater number")
</script>
</body>
</html>
- To check whether, user
entered number is positive or negative.
<!DOCTYPE
html>
<html>
<head>
<title>sop1</title>
</head>
<body>
<h1> To check whether user entered number is positive or negative </h1>
<script language=javascript>
var n
n=prompt("Enter a number","type here")
if(n>0)
document.write(n+ " is positive number")
else
document.write(n+ " is negative number")
</script>
</body>
</html>
2nd and 3rd output ?
ReplyDelete