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

Print Names

The document contains examples of using different JavaScript methods to interact with users and manipulate web pages. It includes getting user input using prompt and confirm boxes, displaying alerts, writing to the document, summing user-provided numbers, and changing HTML elements using innerHTML.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Print Names

The document contains examples of using different JavaScript methods to interact with users and manipulate web pages. It includes getting user input using prompt and confirm boxes, displaying alerts, writing to the document, summing user-provided numbers, and changing HTML elements using innerHTML.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Print names
<html> <body> <script language="Javascript"> var s; s = window.prompt("What is your name ?", "your name here" ); document.writeln( s); </script > </body> </html>

2. Alert
<html> <body> <script language="Javascript"> window.alert ("Hello"); </script> </body> </html>

3. Document.write():
<html> <body> <script language="Javascript"> document.writeln( "<h3>"); document.writeln( "Welcome to JavaScript"); document.write( "</h3>"); </script > </body>

</html>

4. Sum
<html> <body> <script language="Javascript"> var no1,no2, ans; no1 = window.prompt("Give the first number ?", "0" ); // get the first input no2 = window.prompt("Give the second number ?", "0" ); // get the first input ans = parseFloat(no1) + parseFloat(no2);//convert to float and add them document.writeln( ans);// print the answer </script > </body> </html>

5. window.confirm()
<html> <body> <script language="Javascript"> var no1,no2, ans; ans = window.confirm("Are you ready?") if (ans==true) // check users response document.writeln( "Start learning JavaScript"); else document.writeln( "Try later"); </script > </body> </html> <html> <body> <h1>My Web Page</h1> <p id="demo">A Paragraph</p> <button type="button" onclick="myFunction()">Try it</button>

<script> function myFunction() { document.getElementById("demo").innerHTML="My First JavaScript Function"; } </script> </body> </html>

You might also like