Skip to main content

JavaScript Quiz February 9, 2017

1. What is the correct JavaScript syntax to change the content of the HTML element below?

<p id="demo">This is a demonstration.</p>

 A. #demo.innerHTML = "Hello World!";
 B. document.getElementByName("p").innerHTML = "Hello World!";
 C. document.getElementById("demo").innerHTML = "Hello World!";
 D. document.getElement("p").innerHTML = "Hello World!";

2. How do you create a function in JavaScript? {Multi select}

 A. function:myFunction(){}
 B. function myFunction(){}
 C. function = myFunction(){}
 D. myFunction = function(){}

3. How many time demo function will call

demo(false);
function demo(param){
if(param);
else
demo(true);
}

4 What will print in console log

demo();
function demo(){
var a = 20,b=30;
if(a!= 20 & b++ == 30);

console.log(a + ' : ' + b);
}

5. What will print in console log

var qpt = "QualityPointTechnologies";
var result =qpt.substring(7,8);
console.log(result);
a) Po
b) yP
c) oi
d) P

6. Which method use for write on document ?

7. How to get parameter from URL request

Transaction is get method and request is parameter name

www.somesite.com/Transaction?accountID=5

8. What will print in console log

function demo()
{
var qpt = "QualityPointTechnologies";
var pattern = /Point/;

var output= qpt.search(pattern);

console.log("Position-" + output);
}

a) Position-7
b) Position-1
c) null
d) error
9.  Can you write HTML tag inside the javascript ?
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");

a) No
b) Yes
c) Impossible

10. Which of the following is the correct syntax to redirect a url using JavaScript?

A - document.location='http://www.newlocation.com';

B - browser.location='http://www.newlocation.com';

C - navigator.location='http://www.newlocation.com';

D - window.location='http://www.newlocation.com';

11. Which of the following is the correct syntax to print a page using JavaScript?

A - window.print();

B - browser.print();

C - navigator.print();

D - document.print();

Answer

1=c
2=b,d
3=2
4=20 : 31
5 = d
6 = document.write
7 = request.params.accountID
8 = b
9 = b
10 = d
11 = a

Congratulations to Jatin Vyas, Chetan Bharti, Ishita Paliwal and Divya Bharadwaj for winning  JS quiz.

Comments