Name(s) Period Date Assessment - Unit 3 lessons 16-21 1. Which of the following statements about strings in JavaScript is FALSE? a. Strings consist of a sequence of concatenated ASCII characters. b. Strings are indicated by quotation marks. c. Strings cannot include numerical digits. d. A string can be empty, meaning that it contains nothing. e. Strings sometimes include spaces. 2. Which of the following JavaScript statements will result in the following output being displayed to the console? Hello! How are you? a. console.log( Hello! \t How are you? ); b. console.log( Hello! \b How are you? ); c. console.log( Hello! \newline How are you? ); d. console.log( Hello! \n How are you? ); e. console.log( Hello! \nl How are you? ); 3. What is the output of the following JavaScript code segment? var num = 5; var str = hello ; var result = num + str; console.log(result); a. 5hello b. 5 + hello c. error on num + str : type mismatch d. result 4. What is the output of the following JavaScript code segment? var str1 = 5 ; var str2 = 5 ; var result = str1 + str2; console.log(result); a. 10 b. error on str1 + str2 : type mismatch c. 55
d. result 5. Short answer: When should a programmer create a global variable instead of a local variable? 6. A Boolean expression is an expression that evaluates to which of the of the following? a. Yes/Maybe/No b. True/False c. Any Integer d. Integers between 1 and 10 e. Any single character 7. The following JavaScript code segment from App Lab has an error! Trace the code to determine which line the error is on and what the error is. 1 var time = promptnum( What time is it? ); 2 if (time < 10){ 3 settext("textbox", "It is before 10"); 4 else { 5 settext("textbox", It is after 10); 6 a. Line 1 time should be written in quotation marks like this time. b. Line 2 The symbol used should be > instead of < c. Line 4 else must always be followed by another conditional statement d. Line 5 It is after 10pm must be written in quotations. e. Line 5 The settext on line 5 will override the settext on line 3. 8. Short Answer: In the previous class periods, you developed a digital assistant that is able to intelligently respond to a limited set of questions and statements. Assume you have created a much more robust digital assistant with capabilities similar to those of Siri. Describe two possible user inputs: one question that a digital assistant could intelligently answer easily, and another that it could not. Explain what makes the first easy and the second difficult for a digital assistant. (Consider the code used to develop your digital assistant.) 9. The following statements are true about event handlers, if statements, or both in App Lab. Place the letter next to each statement into the appropriate area of the table below.
Statements. A. Runs code in response to a user action B. Runs code in response to statement being evaluated to True. C. Evaluated sequentially once execution is inside the statement D. Can be triggered at any time E. Used to run a block of code True for Event Handlers True for if Statements True for Both Event Handlers and if Statements 10. The human question below has a yes/no answer. Create a flowchart that shows the logical progression of the questions that need to be answered to arrive at yes or no. Your diagram should consider the day of the week, time of day, and account for both possible outcomes. Question Flowchart Should I be at school right now?
11. What is the expected output of the given pseudo code segment? A reference for the pseudo code can be found immediately below the question age < 35 IF (age < 35){ DISPLAY (You are not old enough to be President.) ELSE { DISPLAY (You are old enough to be President!) a. 35 b. true c. false d. You are not old enough to be President. e. You are old enough to be President! Pseudo Code Reference Instruction a < expression IF (condition) { <first block of statements> ELSE{ <second block of statements> DISPLAY (expression) INPUT () condition1 AND condition2 Explanation Evaluates expression and assigns the result to the variable a. The code in first block of statements is executed if the Boolean expression condition evaluates to true; otherwise the code in second block of statements is executed. Displays the value of expression, followed by a space. Accepts a value from the user and returns it. Evaluates to true if both condition1 and condition2 are true; otherwise evaluates to false. 12. Consider the following segment given in pseudo code (see reference from previous question): 1. IF (grade >= 70) 2. { 3. DISPLAY( You passed! ); 4. 5. ELSE 6. { 7. IF(grade < 70){
8. DISPLAY( Time to start studying again! ); 9. What will be displayed if grade is set to 70? a. You passed! b. Time to start studying again! c. You passed! and Time to start studying again! d. Nothing will be displayed e. An error will occur on line 7; you can t have an else inside an if statement 13. Consider the JavaScript code segment below. Which statement should be used in place of <missing code> such that the alarm is set to 9:00 am on weekends, and 6:30 am on weekdays. var day = prompt("what day is it tomorrow?"); if ( <missing code> ){ setalarm = 9:00am ; else { setalarm = 6:30am ; a. day == Saturday b. day == Sunday c. (day == Saturday ) (day == Sunday ) d. (day == Saturday ) && (day == Sunday ) e. day!= Monday 14. A pseudocode program is started below that gets two pieces of input from the user and stores each value in a variable. Continue writing pseudocode to accomplish this task: If the hour is within the school day (8 to 15) then display Nice to see you!, Otherwise, display It s time to go home! DISPLAY ( Enter the hour of day (0 23) ) hour < INPUT () 15. Consider the code segment below given in pseudo code (see reference above). Assuming that variables a, b and c already have numeric values assigned to them, what is the expected output of
this code segment? val < a IF(a < b AND b < c){ val < b; ELSE { IF (a < c AND c < b) { val < c; DISPLAY (val); a. The code will display the middle of all three values b. The code will display the smallest of the three values c. The code will display the largest of the three values d. The code will always display the value stored in variable a e. The code will not display anything due to an error For the next two questions, consider the following JavaScript code segment. var word = prompt( Enter a word ); if( word.length > 10){ console.log( Wow, big word. ); else{ if( word.length < 3 ){ console.log( Did you say something? That was so short. ); else{ if( word.length > 6){ console.log( Use that word on the SAT. ); else{ console.log( I ve never heard that before. ); 16. If the above code segment is run, and hello is entered at the prompt, what will be displayed in the console? a. Wow, big word. b. Did you say something? That was so short. c. Use that word on the SAT. d. I ve never heard that before.
e. Nothing will be printed. 17. If the above code segment is run, and goodbye is entered into the prompt, what will be displayed in the console? a. Wow, big word. b. Did you say something? That was so short. c. Use that word on the SAT. d. I ve never heard that before. e. Nothing will be printed. 18. Consider the following JavaScript code segment. 1. var time = promptnum( What hour is it (on a 24 hour clock)? ); 2. var greeting = ; 3. if (time < 6) { 4. greeting = "It is too early!"; 5. else if (time < 20) { 6. greeting = "Good day!"; 7. else if (time < 10) { 8. greeting = Good morning! ; 9. else { 10. greeting = "Good evening!"; 11. 12. console.log(greeting); Something is wrong with the logic in the program above. For which values of time will the greeting Good Morning be displayed? a. Any time between 6 and 9 b. Any time between 10 and 19 c. Any time between 0 and 20 d. There is no value of time that will result in Good Morning being displayed e. The logic error will cause the program to stop running at line 7. 19. A programmer designed a program for an airline to determine whether there is an extra fee on a checked bag. The logic is shown in the flow chart at right. The code they wrote (see below) runs without error, but unfortunately it does not work as intended.
1. var weight = promptnum("how much does your luggage weigh?"); 2. if (weight > 50){ 3. settext("response", "There is a $25 fee to take this luggage"); 4. else if (weight > 120){ 5. settext("response", "Your luggage is too heavy for this flight"); 6. else { 7. settext("response", "Your luggage is accepted as is"); 8. What is the problem? Consider the list of values below and choose two that if assigned to weight will result in the incorrect message being displayed as the response (choose 2)? a. 30 b. 50 c. 75 d. 125 e. 200 20. For each expression below, circle whether it evaluates to true or false. The variable temperature is initialized as shown. var temperature = 30; Expression Evaluates to (circle one) (temperature > 0) && (temperature < 32) true false (temperature > 0) (temperature < 32) true false (temperature!= 0) && (temperature < 32) true false (temperature == 0) (temperature > 32) true false (temperature < 0) (temperature > 32) true false