Uploaded by redfurysmurf101

practice questions JAVASCRIPT certification

advertisement
CEILING/FLOOR/ROUND SEE RULES BELOW
You are planning to use the Math object in a JavaScript application. You write the following code to evaluate
various Math functions: (100.5)
Ceil 101 <- ALWAYS ROUND UP
Floor 100 <-ALWAYS ROUND DOWN
Round 101 <-round BASED ON NUMBER
MOUSE QUESTIONS
You are creating a dynamic HTML page by using JavaScript.
Your page has an image of the sun. When the user's mouse pointer moves across the image of the sun, the
image should change to the image of the moon.
onmouseout and onmouseover
You are designing a web page that contains a blue button. When the button is pressed, it should call a function
that displays the message "˜Welcome!'. When the cursor hovers over the button, the button should turn red.
When the cursor leaves the button, the button should revert to its original color of blue.
Onclick and onmouseover
SWITCH/CASE/FOR/CONTINUE/BREAK/WHILE/TRY/CATCH QUESTIONS
***The ABC company offers a mid-week discount of 10% on Wednesdays.
Switch (day)
{ case “Wednesday”;
Default
***write a loop that will traverse the length of an array to find the value orange. If
an array element value is null, the code should immediately go to the next element.
When the value is found, the loop should exit.
For
Continue
break
calendar application. You need to ensure that the code works correctly for all
months of the year.
Month= newDate().
Switch (month){
Continue;
Break
You need to write a loop that performs the following tasks
Complete the code by moving the appropriate keywords from the list on the left to the correct positions on the right.
You may use each keyword once, more than once, or not at all
For, while, break
You are designing a function that allows you to perform unit tests on other functions in a library. You will invoke
each library function by using the eval JavaScript function. If an exception occurs when invoking a function,
you want to display a message box with the following message:
The function does not exist.
How should you complete the code? To answer, select the appropriate code segment in the answer area.
NOTE: Each correct selection is worth one point. Hot Area:
Answer: try, catch
TRUE/FALSE QUESTIONS
***While using a GET request with a form, the data length is restricted. T
Only GET requests should be used when handling sensitive. F
Form POSTS requests are cached. F
Form POST requests will always remain in the browser. F
***GIVEN :
Function validatePin(pin)
Var validated =!isNan (pin) && pin.toString().length==4;
Return validate
“ABCD” T
1234 F
20*50 F
01 “use strict” ;
02 var val1=25:
03 var val2=4;
The call to themultiply function on line 09 returns 100 T
The call to themultiply function on line 19 returns 100 F
function that does safe division.
The function will always return false F
The operator at line 02 should be != F
Variable x has a value of 5. Variable y has a value of 7.
X< 7 && y > 6 T
X==6 II y ==6 F
X!==7 T
! (x==y) T
*********************
will submit name contact T
Only submit first & last T
Not submit F
T<T<T,F
TFTF
Function validateCode(code)
Var validated =!isNan (pin) && pin.toString().length==6;
Return validate
ANSWER:
111111 is true T
“012345” is true T
“XYZXYZ” is true T
2000 *300 is true F
BOOLEAN/STRING/NUMBER QUESTIONS
01 var n;
02 console.log (typeof n); undefined
03 var a =”3.4”;
04 console.log (typeof a); string
05 var textArray =[“Welcome Back”, “Enter a Name”, “Incorrect Answer”]:
Line 6:object (array)
line 8: number
Line 10: object
You are writing a JavaScript program for Blue Yonder Airlines. The program stores various information about
the airline"™s flights. The program has initialized the following variables:
Line 1: STRING
Line 3: number
Line 4: Boolean
Line 5: STRING
var age=23; number
var exempt=false; Boolean
var initial= ‘D’: string
var salary=123.5; number
var zip= “81000”, string
WRITING CODE QUESTIONS
You are creating a web page with a script. The script will insert the window's location inside the page's input
element.
document.getElementById("url").value=window.location
****You are designing a web page with a script that must dynamically change the content of a paragraph
element to display the value returned by the function randomQuote()
document.getElementById("tester").innerHTML = randomQuote();
You are designing a web page that contains a list of animals. The web page includes a script that outputs
animals from a list.
getElementsByTagName("ul")
getElementById
innerHTML
inerText
You are writing a JavaScript program for Contoso Suites that will output HTML.
You need to output each room type on a new line using the correct method. You need to insert the correct
code at Line 9. Which line should you use?
document.getElementById("para").innerHTML+=rooms[i]+"<br>";
You are creating a web page that requests a username.
You create the following HTML form:
var username = document.forms.credentials.username.value;
You are using JavaScript to create a calculator.
You create the following HTML. Line numbers are included for reference only.
You must create a function named add() that adds the values in the a and b input elements and displays the
result in the result input element.
var a= eval (document.getElementById (“a”).value);
var b = eval (document.getElementById(“b”).value);
document.getElementById(“result”).value = a + b;
You are creating an application that requires a title and a numbered list.
document.getElementByID("title") textContent="Wish List";
document.getElementByID("showList").value=text;
You need to create and populate a list of customers and identify customers who placed orders in the last 3 years
currentDate.getFullYear()
orderDate.getFullYear()
You are creating a web page that allows customers to choose how hot their spice is. If they choose spicy, a
warning should be displayed. You create the following form. Line numbers are included for reference only.
Change line 10 to var option = document.forms.orderForm["heatIndex"].value;
You are creating a web page that tests a user's ability to accurately type text. The validation should be caseinsensitive.
.value .innerHTML .toLowerCase() .toLowerCase()
You are writing an engineering application. You need to create a function that will round numbers to 3 or more
decimal places.You need to create a function that receives the following two parameters:
✑ The value parameter is the number to be formatted
✑ The digits parameter is the number of digits to display
Function significance (value,digits){return value.toFixed (digits);
You are using JavaScript to write a safe root math utility that has the following requirements:
safeRoot (a, b) If {a >=0){
}else {
If (b% 2==0)
}else {
creating a function named countdown. The function accepts a single parameter, start, and displays a
countdown from that number down to zero in increments of one.
For {var i = start; i>0; --i
You are creating a JavaScript function that returns a date the specified number of months in the future of the
current date.
Var date = newDate();
Var month =date.getMonth();
Date.setMonth (month + value):
You are writing a function that calculates the remainder for integer division. The function receives two
parameters, a and b, and must return the remainder that is left over when the integer a is divided by the integer
b.
You create the following code. Line numbers are for reference only.
You want to complete the function for lines 02 and 03.
Which two sets of code segments should you use? Each correct answer presents a complete solution.
(Choose two.)
02 a =a %b;
03 return a;
AND
And a%=b
Return a
RANDOM ANSWERS
You evaluate the following code:
You need to determine the values of sampleStudent, sampleCourse.name, and sampleCourse.grade that are
output by console.log(). What are the final values for the three variables? To answer, select the appropriate
values in the answer area.
HTML student;Javascript; 100
A JavaScript array is initialized as follows:
You write the following code to manipulate the array:
You need to determine the contents of the array.
Which four elements does the array contain in sequence? To answer, move the appropriate elements from the
list of elements to the answer area and arrange them in the correct order.
100,40,60,10
You want to initialize a Date object with the date January 1, 2021
Var date = new date (2021, 0, 1)
You work as a JavaScript developer for Adventure Works. You are writing a simple script that performs the
following actions:
Var number =[]
For (var i= 0…. Push
For (var j= 0….. j++
Array[j]
a person should take the train, drive their car, or ride a bike
&& and <=
calculates admission price
if (age < 5 || age >=65){ price =0;
if (age >=5 && age < 18); {price =10)
Your instructor has asked you to implement code that would display a two-dimensional array of any size inside
a <div> tag (use the last 3 boxes)
Var x =15;
X%=5
When this code executes, the value x is 0 ……..VALUE 0
How to write the str as empty… ANSWER: str ==””
You are creating a JavaScript program for an accounting system.
You create the following code. Line numbers are included for reference only.
You evaluate the code to ensure that it follows JavaScript best practices.
Which line has Reserved words? Line 3 AND 5
GIVEN: <div id=’sectionA’>
<div id=’section1’>
What method should you use?
ANSWER:getElementId
***DRAG DROP Evaluate the following code. Line numbers are included for reference only.
What is the value of each variable at line 07? To answer, drag the appropriate value to the correct variable.
Each value may be used once, more than once, or not at all. You may need to drag the split bar between
panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place: ANSWER: 10, 55, 0, 5
***problem ticket
ANSWER: onsubmit
You need to create an external Javascript that showArea.
ANSWER: (other answers mention the words ….head or script or body)
Function showArea (length, width) {
Alert (length * width);
}
var x-“10”
var y = x +10
What is y?
ANSWER:1010
ANSWER :40
Several HTTML pages need to reference Javascript code. Where should the JavaScript code live?
Answer: in the js file
It is an infinite loop because …. Sale
is not initiated at 0
You are writing Javascript within a HTTMl document. If Javascript is disabled,the document must display a
message informing the user that they need… Javascript is disabled
ANSWER:noscript
You are creating a dynamic HTML document using Javascript. You need to create a popup window that
displays additional information when the user clicks a button.
ANSWER:window
Function calculate Sum (x, y) {
Cont sum = 0
Try {
x = x * 2;
y= y +5;
--- What happens when calculateSum runs? ANSWER: the sum is returned
You creating a web page that contains a script with a function named calculate
The function will call an inner function based on the operation
return multiply(x, y);
return divide(n, d);
function multiply(a, b){
function divide(a,b){
Creating a script based on user’s age CAT1 CAT2 CAT3
ANSWER: answer above is INCORRECT, it should be if  else if  else
You are writing a JavaScript program. The validGraphic function of the program checks whether the height of a graphic is
equal to or greater than 50 pixels, but less than 100 pixels
HEIGHT >= MIN && <=MAX
DOM tree
document.appendChild (“img”)
Src
querySelector(“body”)
append(newimgElement);
function calculateSum(x,y) {
const sum = 0;
try {
x = x * 2;
y = y + 5;
sum = x + y;
}
catch(error) {
console.log('Error');
}
return sum;
A SYNTAX ERROR occur
You are writing a program that includes an update() function
09 output.innerHTML = input.value;
10 input.hidden = true;
ANSWERS THAT I AM NOT SURE OF/DIDN’T
Download