CSS Practice Questions
CSS Practice Questions
Ans :-
Ans :- While primarily used for input, prompt() can also be used to display output by
showing a message in the prompt dialog.
- Example:
<html>
<head></head>
<body>
<script type="text/javascript">
var arr=new Array ("Red", "Blue", "Green", "Pink", "Yellow");
var i;
document. write ("Array Elements are: ");
for (i=0; i<arr.length;i++)
{
document. write("<br>" + arr[i]);
}
</script>
</body>
</html>
Syntax :-
if (condition) {
// Code to execute if the condition is true
} else {
// Code to execute if the condition is false
}
Example :-
7) List various data types and describe with an example how to declare an integer
variable in java script.
Example :-
<html>
<head></head>
<body>
<script type="text/javascript">
let str = "Deepak";
let result = str.substr(2);
document.write(result);
</script>
</body>
</html>
Output :- epak
Ans :-
push() :- The push() method adds one or more elements to the end of an array and
returns the new length of the array.
Example :-
<html>
<head></head>
<body>
<script type="text/javascript">
let arr = ["Esha","Sanjana","Shweta","Meena"];
let result = arr.push("Sneha","Vaibhavi");
document.write(arr);
document.write("<br>"+result);
</script>
</body>
</html>
Join() :- The join() method creates and returns a new string by concatenating all
elements of an array, separated by a specified separator.
Example :-
<html>
<head></head>
<body>
<script type="text/javascript">
let arr = ["Esha","Sanjana","Shweta","Meena"];
let result = arr.join("&");
document.write(result);
</script>
</body>
</html>
10) Write JavaScript code to create an array with five names of fruits
Ans :-
<html>
<head></head>
<body>
<script type="text/javascript">
var arr = new Array("Apple","Banana","Dragon Fruit","Pineapple","Mango");
var i;
document.write("Array elements are :");
for(i=0; i<arr.length; i++)
{
document.write("<br>"+arr[i]);
}
</script>
</body>
</html>
11) Write a java script code to use a function to multiply two given integers.
Ans:-
<html>
<head>
<script type="text/javascript">
function mul(a,b)
{
var result=a*b;
return result;
}
</script>
</head>
<body>
<script type="text/javascript">
var no1=prompt("Enter first number");
var no2=prompt("Enter second number");
var r=mul(no1,no2);
document.write("Multiplication = " + r);
</script>
</body>
</html>
Ans :-DOM stands for Document Object Model. It's a programming interface for web
documents. When a webpage is loaded into a web browser, the browser creates a DOM
representation of the page in memory. This representation allows JavaScript to access and
manipulate the structure, content, and style of the document.