Javascript

Ace your homework & exams now with Quizwiz!

A

What will be the result of the following code? var number1 = 5; var number2 = 10; var word; if ( number1 > 0 ) { word="blue"; } else if ( number1 > 0 ) { word="red"; } else if ( number1 > 1 ) { word="green"; } alert(word); a. blue b. red c. green d. Error

B

In the following line of code, what does the 'value' term refer to? document.getElementById('txtTelephone').value; a. The name of the form. b. The value typed in the 'txtTelephone' textbox. c. The current document itself. d. The file name of the current document.

NO

Is there a semicolon after a function?

Local: Inside a function Global: Any variable declared outside a function

Javascript has 2 scopes, what are they and what do they encompass?

B

What will be the result of the following code? var number1 = 5; var number2 = 10; var word; if ( number1 > 10 ) { word="blue"; } else if ( number1 > 0 ) { word="red"; } else if ( number1 > 1 ) { word="green"; } alert(word); a. blue b. red c. green d. Error

B Case sensitive

What will be the result of the following code? var d1="Sunday"; var d2="sunday"; if (d1==d2) { alert("hello"); } else { alert("goodbye"); } a. hello b. goodbye c. No error, but no output. d. Error.

True

True or False: If you don't parse a value, it becomes a string?

TRUE

True or False: Multiplication and division have preference over addition and subtraction?

FALSE- only form elements have naming convention

True or False: We have defined a naming convention for form element and variable names.

TRUE

True/False: It is acceptable to have multiple buttons on a page, each of which is connected to a DIFFERENT function.

A

What will be the result of the following code? var number = 10; if (number<5 || number>=10) { alert("hello"); } else { alert("goodbye"); } a. hello b. goodbye c. No error, but no output. d. Error.

D The variable 'word' is never assigned a value

What will be the result of the following code? var number1 = 5; var number2 = 10; var word; if ( number1 < 1 ) { word="blue"; } else if ( number2 < 1 ) { word="red"; } alert(word); a. blue b. red c. word d. Error

D

What will be the result of the following code? var number1 = 5; var number2 = 10; var word; if ( number1 < 1 ) { word="blue"; } else if ( number2 < 1 ) { word="red"; } else { alert("Hello"); } a. blue b. red c. green d. Hello

Assignment Operator

Assigning a value to a variable?

JavaScript

The tool we use to parse forms and react to them?

D Since phone numbers are not quantities, you should not parse this value.

A form element asks the user to enter their telephone number. We retrieve the value using the following line of code: var phone = document.getElementById('txtPhone').value; Which parse function should we use when retrieving this value in your JavaScript? a. parseInt() b. parseFloat() c. parseString() d. No parse function is needed in this situation.

Variable

A programming construct in which you can store information

Domain: depaul.edu Server: condor

Consider the following URL: http://condor.depaul.edu/223/syllabus.htm What is the name of the... Domain? Server?

:"checked" Radiobutton= .checked)

How do you tell if a radio button is checked using the [ ] notation?

A

If an 'if' statement's conditional evaluates to 'true', what happens next? a. The block of the if-statement is executed. The else block (if present) is skipped. b. The block of the if-statement is executed. Then the else block (if present) is executed. c. The program ends. d. None of the above.

C

Imagine that the following two lines of code are placed inside a <script>tag. What is the problem (if any) with this code? <h1>A JavaScript Example</h1> alert("Greetings!"); a. The line of <h1> code is missing a semicolon. b. The alert statement is improperly formatted. c. The script tag should contain only script - HTML will not display. d. There are no problems with this code.

D

In a long if/else-if/else block, under what circumstances does the 'else' block get executed? a. If and only if ALL of the if and else-if conditionals are true. b. If and only if ONE, but no more than one of the previous if or else-if blocks is true. c. If and only if the conditional following the word 'else' evalutes to true. d. If and only if ALL of the previous if and else-if conditionals are FALSE

B n1 is holding the STRING ""10"". n2 is holding the INTEGER 5. When we connect them using the + operator, we get concatenation

In the code below, what will be output by the alert box? var n1, n2, x; n1 = "10"; n2 = 5; x = n1+n2; alert(x); a. 15 b. 105 c. Error d. None of the above.

firstNumber=15 secondNumber=70 if (firstnumber==15 & secondnumber>20)

Make a conditional that both values must be true for the "if" to work?

firstNumber=15 secondNumber=12 if(firstNumber==11 || secondNumber<24

Make a conditional that one of values must be true for the "if" to work?

D Error, b/c the function is called Date() -- with a capital D! Remember that JavaScript is case sensitive.

Recall the function 'Date()' that retrieves the date and time from your computer's internal clock. What will be the output of the following line of code? alert( date() ); a. The date/time from the computer will be output. b. Only the date but not the time will be output. c. The string "date()" will be output. d. Error

B

Suppose you have the following checkboxes in a form: <input type="checkbox" id="chkMushrooms" value="mushrooms"> <input type="checkbox" id="chkOlives" value="olives"> <input type="checkbox" id="chkSausage" value="sausage"> How would you determine if the user had checked the 'mushrooms' checkbox? a. if (document.getElementById('chkMushrooms') == checked) b. if (document.getElementById('chkMushrooms').checked) c. if (document.getElementById('chkMushrooms').value) d. None of the above.

A

Suppose you have the following checkboxes in a form: <input type="checkbox" id="chkMushrooms" value="mushrooms"> <input type="checkbox" id="chkOlives" value="olives"> <input type="checkbox" id="chkSausage" value="sausage"> Is the following block of code valid? if ( document.getElementById("chkMushrooms").checked) alert("You want " + document.getElementById("chkMushrooms").value); else alert("You do not want mushrooms."); a. Yes it is entirely valid. b. No, you will get an error because there are no braces. c. No, you can not use 'value' with a checkbox. d. No, you must use a numeric [0] type prefix with checkboxes.

A The proper syntax is: document.getElementById("radBlue").checked

Suppose you have the following radio buttons in a form: Red<input type="radio" name="favColor" id="radRed"/> <br /> Yellow<input type="radio" name="favColor" id="radYellow"/> <br /> Blue<input type="radio" name="favColor" id="radBlue"/> <br /> How would you determine if the 'Blue' button was chosen by the user? a.if (document.getElementById("radBlue").checked) if (document.getElementById("favColor").checked) c. if (document.getElementById("radBlue").value ==checked) d. None of the above

Operator Precedence

This is the order in which operations are performed in Java.

NaN

This property indicates that a value is not a legal number.

parseFloat()

What function reads through a string and returns a floating point number.

parseInt()

What function reads through a string and returns an integer?

C

What if anything is wrong with the following code? var age = 25; if (age>25); { alert("Hello"); } a. Missing 'else' block. b. The variable 'age' has not been parsed. c. There should not be a semicolon after the conditional. d. There is no error.

B

What if anything is wrong with the following code? var age = document.getElementById('txtAge').value; if (age>25) { alert("Hello"); } else { alert(age); } a. The 'else' block is not allowed to output the 'age' variable. b. The variable 'age' has not been parsed. c. There should be a semicolon after the conditional. d. There is no error.

A

What is the length of the String stored in the following variable? var str = ""; a. 0 b. 1 c. Null d. There is no length - this would be an error.

Do NOT mix it with HTML

What is the main rule about javascript?

5 No quotes. Case sensitive

What is the output of the following line of code? alert( Math.sqrt(25) )

A

What will be generated by the following code: alert( Date() ); a. The date and time in a dialog box b. Date() c. An error d. None of the above

A

What will be output by the following: alert("5+10"); a. 5+10 b. 15 c. 510 d. None of the above, it will generate an error.

A

What will be the output of the following code? var hoursWorked = 40; if (hoursWorked >= 40) { alert("Hello"); } else { alert("Goodbye"); } a. Hello b. Goodbye c. Error - hoursWorked should be parsed to an integer. d. No output

B

What will be the output of the following code? var hoursWorked = 40; hoursWorked = hoursWorked-1; if (hoursWorked >= 40) { alert("Hello"); } else { alert("Goodbye"); } a. Hello b. Goodbye c. Error - hoursWorked should be parsed to an integer. d. None of the above.

A Because the variable number is holding a number -- and not a string -- we get addition.

What will be the output of the following code? var number = 5; var newNumber; newNumber = number + number; alert(newNumber); a. 10 b. 55 c. 7 d. Error

B

What will be the output of the following code? var number = "5"; var newNumber; newNumber = number + number; alert(newNumber); a. 10 b. 55 c. 7 d. Error

A The moment there is a string on either side of the + character, we will get concatenation.

What will be the output of the following code? var str1 = "ABC"; var str2 = "5"; var number = 123; var strTest = str1 + str2 + number; alert( strTest ); a. ABC5123 b. ABC128 c. Error d. None of the above.

A Because we put the entire thing inside quotes, it becomes a string

What will be the output of the following line of code? alert( "Math.sqrt(25)" ); a. The string "Math.sqrt(25)" will be output. b. 5 c. Error d. None of the above.

B

What will be the output of the following line of code? alert(10+"10"); a. 20 b. 1010 c. Error d. None of the above.

B

What will be the result of the following code: var age = 25; if (age>25) { alert("Hello"); } else { alert("Goodbye"); } a. Hello b. Goodbye c. Error d. None of the above.

B When two or more conditions are separated by the logical AND ('&&'), then ALL of the conditions must be true for the whole epxression to be true.

What will be the result of the following code? var number = 10; if (number<20 && number>=15) { alert("hello"); } else { alert("goodbye"); } a. hello b. goodbye c. No error, but no output. d. Error.

C Skip over the 'if' block and continue down the rest of the function.

What will be the result of the following code? var number = 10; if (number<5 && number>=10) //Note: No else here... { alert("hello"); } a. hello b. goodbye c. No error, but no output. d. Error.

A Remember that if you have two or more conditionals separated by logical OR (the '||'), then all you need is for ONE of the conditionals to be true in order for the whole expression to evaluate to true.

What will be the result of the following code? var d1="Sunday"; var d2="sunday"; if (d1==d2 || d1=="Sunday") { alert("hello"); } else { alert("goodbye"); } a. hello b. goodbye c. No error, but no output. d. Error.

D The parseInt function requires that the argument (the value inside the parentheses) begins with either a digit or a minus sign. If it does not, we get an error.

What will be the result of this code? parseInt("four"); a. 4 b. 4.0 c. The string "four" d. Error

D

What, if anything is wrong with the following line of code? var telephoneNumber = document.getElementById('txtTelephone').value; a. telephoneNumber is not a clear identifer. b. A variable cannot be declared on the same line in which it retrieves a value from a form. c. The txtTelephone variable was not declared. d. There is nothing wrong with this line of code.

A

What, if anything, is wrong with the following code? <input type="button" value="Greet Me!" onclick="greetUser"> a. The parentheses are missing after the function identifier (the value of the onclick attribute). b. The onclick attribute should not be used with buttons. c. The greetUser identifier does not follow proper naming conventions.

A 34 is a valid value, but the identifier is poor

What, if anything, is wrong with the following line of code? var function = 34; a. "function" is a reserved word and should not be used as an identifier. b. "function" should be invoked. c. 34 is not a valid value for this variable. d. There is nothing wrong with this line of code.

D

Which of the following is NOT an acceptable way to use a variable? a. To store a numerical value. b. To store the result of a mathematical calculation. c. To store a long String. d. All of the above ARE acceptable ways of using variables.

Undefined

Which property indicates that a variable has not been assigned a value?

D

Why is determining whether a radio button is checked problematic relative to checkboxes? a. Multiple checkboxes can sometimes be given the same name. b. They can not be styled individually. c. You can't allow the user to check the value of a radio button. d. When radio buttons are grouped, they all have the same name.

D Because we commented out the line that does the addition, the interpreter will ignore that line. Therefore, when we output the variable 'newNumber' we will see the 0 that it was initialized to when we declared the variable.

var number = 5; var newNumber = 0; // newNumber = number + number; alert(newNumber); a. 10 b. 55 c. 7 d. 0


Related study sets

CS 2420 - Post-Midterm Exam 2 Material

View Set

2021 Private Pilot Test Prep (Ch 4 & 5, ALL & AIR ONLY)

View Set

Info Sec & Network Quiz Chapter 8

View Set

Nclex review: Pneumonia and Respiratory Meds

View Set

La formation des questions: Posez la question qui a pour réponse l'expression soulignée. Faites les deux versions (et avec "est-ce que", et avec inversion)

View Set

Unit 9 Life insurance underwriting and policy issue

View Set