Java Script questions and answers demo page 2

JavaScript Quiz - Interview questions and answers

Welcome to JavaScript Quiz

1) You are asked by your Software Training Institute website customer to display UX Training certificate course brief details on click of a button on their website, inside the box with the link to an another website, where your visitor know full details and subscribe to course of study. Button name is, "Click for UX Practical Training Course details". Pop up box width is 460px and 460px height. Use DOM - Document Object Model to access the html elements. Visitor has to Double click to close the box or X displayed on left top corner of box. Create a fancy javaScript content box as shown below. Choose correct choice from the three options given below and click Submit button. I had displayed only JavaScript code here as it of JavaScript quiz, no css or html. But, you can view the full demo on click of the button.

Below picture is the output of above demo question.

1. < script >
var button1 = document.getElementById("btn1");
var fancyb = document.getElementById(fbox);
var fclose = document.getElementsByClassName("close")[0];
button1.onclick=function()
{
fancyb.style.display = "block"; }
fancyb.ondblclick=function()
{
fancyb.style.display="none";
}
fancyb.onmouseover=function()
{
fancyb.style.color="maroon";
}
fclose.onclick=function()
{
fancyb.style.display="none";
}
< /script >


2. < script >
var button1 = document.getElementById("btn1");
var fancyb = document.getElementById("fbox");
var fclose = document.getElementsByClassName("close")[0];
button1.onclick=function()
{
fancyb.style.visible = "block"; }
fancyb.ondblclick=function()
{
fancyb.style.display="none";
}
fancyb.onmouseover=function()
{
fancyb.style.color="maroon";
}
fclose.onclick=function()
{
fancyb.style.display="none";
}
< /script >

3. < script >
var button1 = document.getElementById("btn1");
var fancyb = document.getElementById("fbox");
var fclose = document.getElementsByClassName("close")[0];
button1.onclick=function()
{
fancyb.style.display = "block"; }
fancyb.ondblclick=function()
{
fancyb.style.display="none";
}
fancyb.onmouseover=function()
{
fancyb.style.color="maroon";
}
fclose.onclick=function()
{
fancyb.style.display="none";
}
< /script >



X

Google UX Design Certificate

Get started in the fast-growing field of user experience (UX) design with a professional certificate developed by Google. Learn the foundations of UX design, including empathizing with users, building wireframes and prototypes, and conducting research to test your designs.

Click for details

2) You are asked by your website customer to provide the facility of designing of image on the web page to their visitors. Image can be of square, rectangle shape according to the size feeded by them. Details such as image width, height, line width, background color must be entered by the visitor and output must be as shown below. Write a code in JavaScript. I had displayed the three options. Please select the correct option and click Submit button.

Below displayed picture is the output of above demo question. It is 410px width and height. Line width is 15px (Black color border). Background color is hotpink. User may download the picture by write clicking and selecting Save image as... option.

1.
< script >
function drawrectangle() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var rw = prompt("Enter Width. Maximum size 420");
var rh = prompt("Enter Height. Maximum size 420");
context.rect(50, 50, rw, rh);
var lw = prompt("Enter Line Width")
context.lineWidth = lw;
var fs = prompt("Enter Valid Background Color. For example, green, blue");
context.fillStyle = fs;
context.fill();
context.stroke();
};
< /script >

2.
< script >
function drawrectangle() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var rw = prompt("Enter Width. Maximum size 420");
var rh = prompt("Enter Height. Maximum size 420");
context.rect(50, 50, width, rh);
var lw = prompt("Enter Line Width")
context.lineWidth = lw;
var fs = prompt("Enter Valid Background Color. For example, green, blue");
context.fillStyle = fs;
context.fill();
context.stroke();
};
< /script >

3.
< script >
function drawrectangle() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var rw = prompt("Enter Width. Maximum size 420");
var rh = prompt("Enter Height. Maximum size 420");
context.rect(50, 50, rw, height);
var lw = prompt("Enter Line Width")
context.lineWidth = lw;
var fs = prompt("Enter Valid Background Color. For example, green, blue");
context.fillStyle = fs;
context.fill();
context.stroke();
};
< /script >




3) Continuing the above JavaScript program how to catch the error and display appropriate alert message to the visitor. Width must not be more than 420px, empty value not allowed, other than number also not allowed. Program must alert error messages, but allowed to continue. Choose correct option from below given choices.

1.
< script >
function drawrectangle1() {
var canvas = document.getElementById("myCanvas1");
var context = canvas.getContext("2d");
var rw = prompt("Enter Width. Maximum size 420");
try {
if(rw == "") throw "You have not entered enything, cannot be empty";
if(isNaN(rw)) throw "You have not entered number, enter only number";
rw = Number(rw);
if(rw > 420) throw "Width is more than 420px, allowed is upto 420px.";
}
catch(err) {
alert(err);
}
finally {
alert("You have entered number: " + rw + px );
}
var rh = prompt("Enter Height. Maximum size 420");
context.rect(50, 50, rw, rh);
var lw = prompt("Enter Line Width")
context.lineWidth = lw;
var fs = prompt("Enter Valid Background Color. For example, green, blue");
context.fillStyle = fs;
context.fill();
context.stroke();
};
< /script >

2.
< script >
function drawrectangle1() {
var canvas = document.getElementById("myCanvas1");
var context = canvas.getContext("2d");
var rw = prompt("Enter Width. Maximum size 420");
try {
if(rw == "") throw "You have not entered enything, cannot be empty";
if(isNaN(rw)) throw "You have not entered number, enter only number";
rw = Number(rw);
if(rw > 420) throw "Width is more than 420px, allowed is upto 420px.";
}
catch(err) {
alert(err);
}
finally {
alert("You have entered number: " + rw + "px" );
}
var rh = prompt("Enter Height. Maximum size 420");
context.rect(50, 50, rw, rh);
var lw = prompt("Enter Line Width")
context.lineWidth = lw;
var fs = prompt("Enter Valid Background Color. For example, green, blue");
context.fillStyle = fs;
context.fill();
context.stroke();
};
< /script >

3.
< script >
function drawrectangle1() {
var canvas = document.getElementById("myCanvas1");
var context = canvas.getContext("2d");
var rw = prompt("Enter Width. Maximum size 420");
try {
if(rw == "") throw "You have not entered enything, cannot be empty";
if(isNaN(rw)) throw "You have not entered number, enter only number";
rw = Number(rw);
if(rw > 420) throw "Width is more than 420px, allowed is upto 420px.";
}
catch(err) {
alert(err);
}
finally {
alert("You have entered number: " + rw + "px" );

var rh = prompt("Enter Height. Maximum size 420");
context.rect(50, 50, rw, rh);
var lw = prompt("Enter Line Width")
context.lineWidth = lw;
var fs = prompt("Enter Valid Background Color. For example, green, blue");
context.fillStyle = fs;
context.fill();
context.stroke();
};
< /script >





4) You're designing a Website for a School. Head Master of that school has decided to provide a quiz on their website. Question is - When is the National Space Day of India. Provide two chances to answer. Write a code in JavaScript to implement this General Knowledge quiz program on school website to the satisfaction of Head Master.
On click of a button, JavaScript prompt window must show on the screen and initiate the process.

Select the correct option from below three radio buttons and click the Submit button.


1.
< script >
function spacedayIndia()
{
var question = "When is the National Space Day of India";
var canswer = "August 23";
var cresponse = prompt(question, "Input full month name in characters, followed by day as number");
for (count = 0; count < 3; count++);{
if(cresponse != canswer) {
confirm("Wrong answer, Press OK for another opportunity");
var cresponse = prompt(question, "Type your answer here.");
if (count == 1)
{
alert("Good Luck for next time.");
}
}
else {
alert("Good, Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to you as well as to Scientist");
}
if(cresponse == canswer)
{
document.write("You are correct - Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to you as well as to Scientist");
}
else {
document.write("Second time also you are wrong. Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to Scientist!");
}
}
}

2.
< script >
function spacedayIndia()
{
var question = "When is the National Space Day of India";
var canswer = "August 23";
var cresponse = prompt(question, "Input full month name in characters, followed by day as number");
for (count = 0; count < 3; count==);{
if(cresponse != canswer) {
confirm("Wrong answer, Press OK for another opportunity");
var cresponse = prompt(question, "Type your answer here.");
if (count == 1)
{
alert("Good Luck for next time.");
}
}
else {
alert("Good, Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to you as well as to Scientist");
}
if(cresponse == canswer)
{
document.write("You are correct - Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to you as well as to Scientist");
}
else {
document.write("Second time also you are wrong. Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to Scientist!");
}
}
}

3.
< script >
function spacedayIndia()
{
var question = "When is the National Space Day of India";
var danswer = "August 23";
var cresponse = prompt(question, "Input full month name in characters, followed by day as number");
for (count = 0; count < 3; count==);{
if(cresponse != canswer) {
confirm("Wrong answer, Press OK for another opportunity");
var cresponse = prompt(question, "Type your answer here.");
if (count == 1)
{
alert("Good Luck for next time.");
}
}
else {
alert("Good, Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to you as well as to Scientist");
}
if(cresponse == canswer)
{
document.write("You are correct - Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to you as well as to Scientist");
}
else {
document.write("Second time also you are wrong. Prime Minister of India, Honorable Shree Narendra Modi declared August 23 as National Space Day to commemorate the remarkable achievement of Chandrayaan-3's landing on the moon. Kudos to Scientist!");
}
}
}



5) You're designing a Website for a Consumer Electronic Products Wholesaler. One of the director has asked you to implement a on click pop-up window on their product web page, which will close automatically after 8 seconds. That pop-up window will diplay a special discount scheme information for one of their slow moving product - WashClean Washing Machine.
Write a code in JavaScript.

Select the correct option from below three radio buttons and click the Submit button.


1.
< script >
function windowopen()
{
var w = window.open('Special Discount','Auto Close Window','width=200,height=300')
var washmachinecost = "at Rs. 5000.";
const d = new Date();
w.document.write("< h2 >< marquee >*** *** *** ***< /marquee >
WashClean Washing Machine is available on 60% discount " + washmachinecost + " Hurry offer ends soon
< marquee > *** *** *** ***< /marquee >< /h2 >")
w.focus()
setTimeout(function() {w.close();}, 8000)
}
< /script >
2.
< script >
function windowopen()
{
var w = https('Special Discount','Auto Close Window','width=200,height=300')
var washmachinecost = "at Rs. 5000.";
const d = new Date();
w.document.write("< h2 >< marquee >*** *** *** ***< /marquee >
WashClean Washing Machine is available on 60% discount " + washmachinecost + " Hurry offer ends soon
< marquee > *** *** *** ***< /marquee >< /h2 >")
w.focus()
setTimeout(function() {w.close();}, 8000)
}
< /script >
3.
< script >
function windowopen()
{
var w = window.open('Special Discount','Auto Close Window','width=200,height=300')
var washmachinecost = "at Rs. 5000.";
constant d = new Date();
w.document.write("< h2 >< marquee >*** *** *** ***< /marquee >
WashClean Washing Machine is available on 60% discount " + washmachinecost + " Hurry offer ends soon
< marquee > *** *** *** ***< /marquee >< /h2 >")
w.focus()
setTimeout(function() {w.close();}, 8000)
}
< /script >


Calculate Square



Square

Action

(Default Value is Double):

Output:


JavaScript Question and Answers with Demo will continue... Thanks



Microsoft Azure Hackathon for women

Please click here to participate in the above Women's coding competition. We thank TechGig and Microsoft Corporation for this great opportunity.

Google Keynote 2022
Honorable Mr. Sundar Pichai - CEO of great Google in Google I/O 2022 Keynote. #GoogleIO Please click to proceed...



Google Workspace Summit Asia Pacific

Digital Technology Event

Join us at the Google Workspace Summit Asia Pacific on 31 May, Tuesday to discover how organizations of all sizes are building productive, secure, and flexible work environments – from any device, and any location. Hear from Google executives and customers about the latest collaboration tools and innovations that can empower your teams to do their best work. Know more...

YOU CAN WATCH THE ABOVE EVENT BY REGISTERING ON DEMAND. IT'S AVAILABLE ON THE WEBSITE. Click here...

Comments

  1. Hello, this article is very good. I also recommend you to read about Artificial Intelligence for Software Testing approaches.

    ReplyDelete
  2. 5 Reasons to hire React Js Developer

    React is a JavaScript-based UI development library. Facebook and an open-source developer community run it.
    Fast rendering
    It’s easy to learn
    Build elegant React js UI
    Allows writing custom components
    Elevates React js developers' productivity.


    If you are looking certified & experienced ReactJs developer to build your highly attractive website/application so feel free to contact Devstringx technologies, which offers the best react js development services in India.

    ReplyDelete

Post a Comment

Popular posts from this blog

JavaScript question and answer with demo page - 1

Google Career Certificates: Vishnu