Assessment - Unit 3 lessons 16-21

Similar documents
Intro to Event-Driven Programming

Lab 1 Concert Ticket Calculator

Introduction to Programming in Turing. Input, Output, and Variables

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

CSE 1223: Introduction to Computer Programming in Java Chapter 3 Branching

Computers and FORTRAN Language Fortran 95/2003. Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes. Topics:

CS 106 Introduction to Computer Science I

CSCI 150: Exam 1 Practice

CSCI 150: Exam 1 Practice

Pseudocode. ARITHMETIC OPERATORS: In pseudocode arithmetic operators are used to perform arithmetic operations. These operators are listed below:

3 The Building Blocks: Data Types, Literals, and Variables

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

ITEC136 - Lab 2 Population

Control Structures in Java if-else and switch

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Decision Structures. Chapter 4

CS 115 Lecture 4. More Python; testing software. Neil Moore

CS 115 Lecture 8. Selection: the if statement. Neil Moore

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

CSCI 150: Exam 1 Practice

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

c122mar413.notebook March 06, 2013

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

BUP2 5/2 12/4/07 12:49 AM Page 1. Introduction

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

Comp 151. Control structures.

(the bubble footer is automatically inserted into this space)

Text Input and Conditionals

boolean & if-then-else

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

CMPT 120 Introduction To Computing Science And Programming I. Pseudocode. Summer 2012 Instructor: Hassan Khosravi

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

Python for Non-programmers

Assessment - Unit 3 lessons 9-15

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Chapter 2.4: Common facilities of procedural languages

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

Lecture 3. Input, Output and Data Types

Functions and Arrays Programs

JavaScript Basics. The Big Picture

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Introducing: main Function, Comments, Statements

AQA Decision 1 Algorithms. Section 1: Communicating an algorithm

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

From video conversation 2. This is a gap fill exercise and can be used as either a quiz/test of

St. Benedict s High School. Computing Science. Software Design & Development. (Part 1 Computer Programming) National 5

Input, output, and sequence

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

Lesson 5C MyClass Methods. By John B. Owen All rights reserved 2011, revised 2014

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

New Permit Request Guide

Intro. Scheme Basics. scm> 5 5. scm>

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

Expressions and Variables

Flow Chart. The diagrammatic representation shows a solution to a given problem.

Lesson 5 Cloud Upload

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

Maxime Defauw. Learning Swift

Lab 2 Population. Purpose. Assignment Lab 2 analyzes population growth of a town as well as compare the population growth of two towns.

Selection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING

JavaScript s role on the Web

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Lesson 7: If Statement and Comparison Operators

CMSC 201 Spring 2017 Lab 01 Hello World

Using System.out.println()

Cambridge International Examinations Cambridge Ordinary Level

Variables and Typing

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

Administrativia. CS107 Introduction to Computer Science. Readings. Algorithms. Expressing algorithms

Decisions, Decisions. Testing, testing C H A P T E R 7

LOOPS. Repetition using the while statement

Algorithm Discovery and Design. Why are Algorithms Important? Representing Algorithms. Chapter 2 Topics: What language to use?

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

A quick look at the basic functions of the Hercules Programmable Controller by

CS Introduction to Programming Fall 2016

Computer Science 202 Introduction to Programming The College of Saint Rose Fall Topic Notes: Conditional Execution

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Elementary Computing CSC 100. M. Cheng, Computer Science

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

Fundamentals of Structured Programming

A control expression must evaluate to a value that can be interpreted as true or false.

Logic & Algorithms Foundations of Computer Science Behrouz A. Forouzan, Brooks/Cole Thomson Learning, Pacific Grove, USA, 2003.

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark]

JavaScript 1 Instructions

Decisions in Java Nested IF Statements

Chapter 1: Problem Solving Skills Introduction to Programming GENG 200

New Permit Request Guide

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Transcription:

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