Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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