CS - JavaScript
CS - JavaScript
1. document.write()
The document.write() method is used for displaying the text on the browser window. It uses
an object called document, which refers to the current document on the browser window.
2. window.prompt()
The prompt dialog box is also a method of the window object. This method is used for
getting input from the user. It displays a Explorer User Prompt dialog box with a message, and
an input field.
3. window.alert()
window.alert () is a method of the window object. It is the simplest dialog box used to display a
short message to the user in a separate small window. The dialog box contains the text given as
a parameter to the alert( ) method and a button labelled OK.
4. window.confirm()
This method returns true if OK is pressed and false if Cancel is pressed.
5. parseInt()
parseInt() method converts a string value into integers (numbers without decimal places)
6. parseFloat()
parseFloat() method converts a string value into floating numbers (numbers with decimal
values).
D. Answer the following questions.
A. Write a JavaScript program to input marks of all your subjects and then calculate the
average.
Ans:
<html>
<body>
<script language="JavaScript">
var Myanmar = Number(prompt("Enter the marks of Myanmar"));
var English = Number(prompt("Enter the marks of English"));
var Mathematics = Number(prompt("Enter the marks of
Mathematics"));
var Physics = Number(prompt("Enter the marks of Physics"));
var Chemistry = Number(prompt("Enter the marks of
Chemistry"));
var Biology = Number(prompt("Enter the marks of Biology"));
var Computer_Science = Number(prompt("Enter the marks of
Computer Science"));
var Social_Studies = Number(prompt("Enter the marks of Social
Studies"));
var Art = Number(prompt("Enter the marks of Art"));
C. Input the first name and last name from the user and display a message "The name
you entered is <first name><last name>" .
Ans:
<html>
<body>
<script lang="Javascript">
var firstname,lastname
firstname=prompt("Enter your first name")
lastname=prompt("Enter your last name")
document.write("The name you entered is, " + firstname + " " +
lastname + " ")
</script>
</body>
</html>
D. Input your school name and display it in red and in a bigger font size.
Ans:
<html>
<body>
<script lang="Javascript">
var schoolname = prompt("Enter your school name:");
document.write("<h1 style='color:red;'>Your school name is: " +
schoolname + "</h1>");
</script>
</body>
</html>