SOP 1: Create a JavaScript program for the following using
appropriate variables, JavaScript inbuilt functions, and control
structures.
To accept an integer and display the result by multiplying it with 3.
To accept two integers and display a larger number of them.
To check whether the user entered number is positive or negative.
Answer:
To accept integer and display the result by multiplying it with 3.
<!DOCTYPE html>
<head>
<title>To accept integer and display the result by multiplying it with
3.</title>
</head>
<body>
<script language=”javascript”> var a,no,ans;
a=prompt(Enter any value‟);
no=parseInt(a);
ans=no*3;
document.
write(“The answer is :”+ans);
</script>
</body>
</html>
To accept two integers and display larger number of them.
<!DOCTYPE html>
<head>
<title>To accept two integers and display larger number of them.</title>
</head>
<body>
<script language=”javascript”>
var a,b;
a=prompt(„Enter first value‟);
b=prompt(„Enter second value‟);
if(a>b)
document.write(“a is large number than b “);
else
document. write(“b is large number than a”);
</script>
</body>
</html>
To check whether, user entered number is positive or negative.
<!DOCTYPE html>
<head>
<title>To check whether, user entered number is positive or
negative</title>
</head>
<body>
<script language=”javascript”>
var a,no;
a=prompt(„Enter any number‟);
no=parseInt(a);
if(no>0)
document.write(“Number is Positive”);
else
document.write(“Number is Negative”);
</script>
</body>
</html>