1. Program to print hello world
<html>
<body>
<script type="text/javascript">
document.write("hello World");
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
document.write("hello World");
</script>
</body>
</html>
2. Program to swap two strings.
<html>
<head>
<script> function swap()
{
var txt = document.getElementById('t1').value;
document.getElementById('t1').value = document.getElementById('t2').value; document.getElementById('t2').value = txt;
}
</script>
</head>
<body>
<input type="text" id="t1"> <input type="text" id="t2">
<br>
<input type="button" value="Swap" onclick="swap()">
</body>
</html>
<html>
<head>
<script> function swap()
{
var txt = document.getElementById('t1').value;
document.getElementById('t1').value = document.getElementById('t2').value; document.getElementById('t2').value = txt;
}
</script>
</head>
<body>
<input type="text" id="t1"> <input type="text" id="t2">
<br>
<input type="button" value="Swap" onclick="swap()">
</body>
</html>
3. Program to add text to a particular division in the page.
<script>
function add1()
{
document.getElementById('div1').innerHTML = document.getElementById('t1').value
}
</script>
<input type="text" id="t1"> <br> <input type="button" value="Click" onclick="add1()"> <div id="div1">
</div>
<script>
function add1()
{
document.getElementById('div1').innerHTML = document.getElementById('t1').value
}
</script>
<input type="text" id="t1"> <br> <input type="button" value="Click" onclick="add1()"> <div id="div1">
</div>
What shows in the console?
console.log(typeof false);
console.log(typeof false);
Anonymous Quiz
9%
Number
13%
Null
23%
Undefined
56%
Boolean
Program to change style of a text at runtime.
<script>
function chngstyle()
{
document.getElementById('div1').style.color = "Red"
document.getElementById('div1').style.backgroundColor = "yellow"
document.getElementById('div1').style.width = "100"
document.getElementById('div1').style.height = "100"
}
</script>
<div id="div1"> Welcome to all </div>
<input type="button" value="Click" onclick="chngstyle()">
<script>
function chngstyle()
{
document.getElementById('div1').style.color = "Red"
document.getElementById('div1').style.backgroundColor = "yellow"
document.getElementById('div1').style.width = "100"
document.getElementById('div1').style.height = "100"
}
</script>
<div id="div1"> Welcome to all </div>
<input type="button" value="Click" onclick="chngstyle()">
In JavaScript same variable can be used for different types. True or False?
Anonymous Quiz
69%
True
31%
False
🔰 CSS Basic Quiz
Browser adds some default stylesheets. True or False?
Browser adds some default stylesheets. True or False?
Anonymous Quiz
80%
True
20%
False