[Go to site: main page, start]

0% found this document useful (0 votes)
5 views3 pages

JavaScript Practice Codes

The document provides several JavaScript code examples for practicing basic programming concepts. These include displaying messages, taking user input, performing arithmetic operations, and using alert and confirm dialogs. Each example is structured within HTML to demonstrate how JavaScript interacts with web pages.

Uploaded by

muntuhaque1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

JavaScript Practice Codes

The document provides several JavaScript code examples for practicing basic programming concepts. These include displaying messages, taking user input, performing arithmetic operations, and using alert and confirm dialogs. Each example is structured within HTML to demonstrate how JavaScript interacts with web pages.

Uploaded by

muntuhaque1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Some JavaScript code for Practice:

❖ Write a JavaScript program to display a message on a web page.


<html>
<body>
<script>
[Link]("Hello World");
</script>
</body>
</html>
❖ Write a JavaScript program to display a heading and bold text.
<html>
<body>
<script>
[Link]("<h1>JavaScript</h1>");
[Link]("<b>Lab Exam Program</b>");
</script>
</body>
</html>
❖ Write a JavaScript program to display an alert message on button click.
<html>
<body>
<button Me</button>
<script>
function showAlert() {
alert("Button clicked!");
}
</script>
</body>
</html>
❖ Write a JavaScript program to take name from user using prompt() and
display it.
<html>
<body>
<script>
var name = prompt("Enter your name");
[Link]("Welcome " + name);
</script>
</body>
</html>
❖ Add two numbers using prompt() and display the result.
<html>
<body>
<script>
var a = prompt("Enter first number");
var b = prompt("Enter second number");
var sum = parseInt(a) + parseInt(b);
[Link]("Sum = " + sum);
</script>
</body>
</html>
❖ Take text input and display it using button click.
<html>
<body>
<h2>Enter your name</h2>
<input type="text" id="name">
<button > <script>
function showmessage(){
var n = [Link]("name").value;
[Link]("Welcome" + n);
}
</script>
</body>
</html>
❖ Use confirm() method and display the result.
<html>
<body>
<script>
var reply = confirm("You must always follow the traffic rules");
[Link](reply);
</script>
</body>
</html>
❖ Display variable values using JavaScript.
<html>
<body>
<script>
var name = "John";
var age = 12;
[Link]("Name: " + name + "<br>");
[Link]("Age: " + age);
</script>
</body>
</html>
❖ Write a JavaScript program using arithmetic operators.
<html>
<body>
<script>
var a=2
var b=10
[Link](“The addition of two number is=”);
var result=a+b
[Link](“result”);
[Link](“<br>The multiplication of two number is=”);
var result=a*b
[Link](“result)
</script>
</body>
</html>

You might also like