Programming Midterm

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is returned from the function reduce following execution function reduce(array, combine, start) { let current=start; for (let element of array) { current = combine(current, element); } return current; } reduce([1,2,3,4,5], (a, b) => a + b, 0); -1 -5 -10 -15

15

In the following code, what does n represent? function repeat(n, action) { for (let i=0; i<n; i++) { action (i) } } repeat(3, console.log); -i -3 -console.log

3

For the while loop below, how many times does this loop execute? var i = 0; while (i < 4) { console.log("hello"); i++; } - 0 times - 4 times - 5 times - an infinite number of times

4 times

What is the number is alerted? var sum = 10; var addNumbers = function (first, second) { var sum = first + second; return sum; } sum = addNumbers( 4, 5); sum = addNumbers(2, 3); console.log(sum); -9 -10 5 -9 then 5

5

JavaScript has a predefined order of precedence. Multiplication and division are executed prior to addition and subtraction. The JavaScript expression below evaluates to: 3 + 6 / 2 -15 -6 -18

6 (6/2 = 3) + 3 = 6

What is the number is alerted? var sum = 10; var addNumbers = function (first, second) { var sum = first + second; return sum; } sum = addNumbers( 4, 5); console.log(sum); sum = addNumbers(2, 3); -9 5 -10 -9 then 5

9

What is the output of the following code? console.log("90" + "95") -185 -string -number -9095

9095 these are strings. so we do not mathematically add them. we "glue" them together.

What number will alert from the array? var testScores = [ 95, 89, 92]; var poppedOne = testScores.pop(); console.log(poppedOne); -95 -89 -92 -all

92

The array has a property that stores the number of values that are in the array called: -size -lenght -count

length

forEach

loops over elements in an array

If you put this keyword in front of a function call, it is treated as a constructor. -new -this -type -let

new

The following values are all of type: 5 15.67 3.001e7 -boolean -string -number -text

number

Which is a valid notation for accessing object properties? -object.propert -object {property} -object (property)

object.property

What is the result of the following code: var calcTotal = function(price, couponAmount ){ var price = 30; var couponAmount = 10; return price - couponAmount ; } console.log( calcTotal(50,10) ); -One alert with message: 20 - First alert with message: 20 Second alert with message: 40 - no alerts

one alert with message: 20

an array is created by using: -curly braces {} -angle brackets <> -parentheses () -square brackets [ ]

[ ]

interfaces

abstract functions or bindings that hide their precise implementation

public

accessible properties

var testScores = [ 95, 89, 92]; To add a value to testScores, use the following syntax. -testScores[3] = 97; -testScores.push(97); -testScores[10] = 97;

all are correct

An array can be created with a list of values as follows: -var list = [ true, false, "4"]; -var list = [ 1, 22, 45]; -var list = [ "a", "b", "c"]

all are true

Object-oriented programming: -can be used with JavaScript programming. -focuses on the objects first. -puts the funtionality of the objects together with its properties.

all the above

For the while loop below, what code is executed when the condition is true (choose the completely correct answer)? var i = 0; while (i < 4) { console.log("hello"); i++; } - var I = 0 - everything between the {} - I++; console.lof(hello)

everything between the {}

Functions can only be executed once -true -false

false

Higher-order functions allow abstraction on values only, not actions true or false

false

Methods are properties that hold integer values. true or false

false

This code will define a function which calculates a price with tax that can be executed later in the program. var calculatePriceWithTax = function () { var price = 10; var tax = .055; console.log("The total is $" + (price + price*tax).toFixed(2)); } -true -false

false

Variables declared inside a function can also be used outside of a function. -false -true

false

Which loop will alert all of the numbers in the array? var testScores = [ 95, 89, 92]; testScores.push(87); -for (var i=0; i<testScores.length; i++) { alert(testScores[0]); } -for (var i=0; i<testScores.length; i++) { alert(testScores[i]); }

for (var i=0; i<testScores.length; i++) { alert(testScores[i]); }

An array is a special type of an object in JavaScript that -is either true or false. -holds multiple values -holds strings only -holds numbers only

holds multiple values

private

properties not to be touched

Which of the following is NOT part of the Map object interface? -has -put -get -set

put

Which of the following functions is NOT available through the Math object? -sqrt -cos -min -return

return

Programming style and guidelines are valuable because it makes the code easier to read and understand. -true -false

true

Prototypes are used as a default source of properties. true or false

true

The && is the logical and operator that only returns true if both sides are true. True or false.

true

The JavaScript type of the value "Good Morning" is a String. true or false.

true

The JavaScript type of the value 4.56 is a Number. true or false.

true

The JavaScript type of the value of the keyword true is a Boolean. true or false.

true

The following code will not change the values of x or y from the initial value of 1 because x is not equal to 2. var x=1;var y=1; if ( x==2) {y=2;} - true -false

true

The order of precedence can affect type coercion of an expression. True or false.

true

The toString method may be overridden in object prototypes. true or false

true

You may use the JavaScript console to determine the type of any value, expression, or variable by use the typeof function. true or false.

true

constructor

ensures that each specific implementation of an object has the properties it should

JSON is a syntax for storing and exchanging object data in JavaScript. -true -false

true

JavaScript is case sensitive which means that the variable xPos is not the same as xpos. -true -false

true

NaN is a special value for type Number when the expression does not evaluate to a number. true or false.

true

In the following code, what does args represent? function noisy(f) { return(...args) => { console.log("calling with", args); let result = f(...args); console.log("called with", args, ", returned", result); return result; }; } noisy(Math.min)(3,2,1); -1 -(3,2,1) Math.Min -result

(3,2,1)

In the following code, what does combine represent? function reduce(array, combine, start) { let current=start; for (let element of array) { current = combine(current, element); } return current; } reduce([1,2,3,4,5], (a, b) => a + b, 0); -[1,2,3,4,5] -(a, b) -(a, b) => a+b

(a, b) => a+b

What is the value of discountPercent after the following code is run? var discountPercent = 10; var calcDiscount = function () { taxPercent = 5.5; var price = 100; var salesPrice = price - price*discountPercent /100; var finalCost = salesPrice * (1 + taxPercent/100) return finalCost; } console.log("Final cost is $" + calcDiscount().toFixed(2)); -10 -90 -0.1 -94.95

10

What is the output of the following code? console.log(90 / 100) -90 -90100 -0.9

0.9

The if statement provides the capability for (check all that apply): 1. the programmer to add code to be executed only if a condition is true. 2. the programmer to test a condition by using the comparison operator. 3 the programer to repeat the execution of a block of code . 4. the programmer to store into in computer memory

1. the programmer to add code to be executed only if a condition is true. 2. the programmer to test a condition by using the comparison operator.

Which symbol can be used to check if two values are equal in a comparison? = == !== !=

==

Comments should be (Select all that apply): - descriptive of the functionality - provide meaning as it applies to the program - provide value in understanding the meaning of the code - All the above

All the above

What type does the following JavaScript expression evaluate to? 3 != 5 -String -Boolean -Undefined

Boolean != is a boolean

What does the following code do? price1 = 10; price2 = "$9.99" console.log(price1 + price2); - Displays: $19.99 -Displays: 19 -Displays: 19.99 -Displays: 10$9.99

Displays 10$9.99

For the while loop below, what is the condition that has to be true for the loop to execute? var i = 0; while (i < 4) { console.log("hello"); i++; } - var i = 0 - I < 4 I++;

I < 4

In the following code, what does f represent? function noisy(f) { return(...args) => { console.log("calling with", args); let result = f(...args); console.log("called with", args, ", returned", result); return result; }; } noisy(Math.min)(3,2,1); -1 -(3,2,1) Math.Min -result

Math.min

What type does the following JavaScript expression evaluate to? -String -undefined -boolean

String

The following code will show "Hello" var condition= false;if (condition) {console.log("Hello");} else {console.log("Good-bye");} - true - false

True

var balloonSize = 6; Which line of code will add 1 to balloonSize and store the incremented value back into balloonSize changing the value of balloonSize to 7. - balloonsize = balloonsize + 1; -balloonSize = balloonSize + 5; -var balloonSize2 = balloon size + 1; - balloonSize = balloonSize +1

balloonSize = balloonSize +1;

The following values are all of type: true & false -boolean -text -sting

boolean

What type does the following JavaScript expression evaluate to? true

boolean

reduce

combien all elemetens in an array to a single value

In the following code, what does action represent? function repeat(n, action) { for (let i=0; i<n; i++) { action (i) } } repeat(3, console.log); -i -3 -console.log

console.log

prototype

default source of properties

class

defines what methods or properties a object has

Which variable has global scope? var discountPercent = 10; var calcDiscount = function () { var taxPercent = 5.5; var price = 100; var salesPrice = price - price*discountPercent /100; var finalCost = salesPrice * (1 + taxPercent/100) return finalCost; } console.log("Final cost is $" + calcDiscount().toFixed(2)); -discountPercent -price -salesPrice -Finalcost

discountPercent

filter

returns a new array containing only elements which pass the predicate function

findIndex

returns the position of the first element which matches a predicate

What determines where a variable can be accessed? -type -scope -name -value

scope

encapsulation

separating code from implementation

instance

specific implementation of an object

Which of the following is a string method to separate a string on every occurrence of another string? -split -join -trim -slice

split

var testScores = [ 95, 89, 92]; To get the value of the property length from testScores, use the following syntax.

testScores.length

var testScores = [ 95, 89, 92]; To remove the last value from the array, use the following syntax.

testScores.pop();

var testScores = [ 95, 89, 92]; To change the value 89 to 91 in testScores, use the following syntax. -testScores.push(91); -testScores[2]=91 -testScores[1]=91;

testScores[1]=91;

some

tests whether any element matches a given predicate function

map

transforms an array by putting each element through a function

Which of the following is a string method to remove white space? -split -join -trim -slice

trim

A function defines a block of statements (JavaScript code) that is saved to a variable name and can be run later. -true -false

true

Abstractions hide details and provide the ability to consider problems at a higher level. true or false

true

An iterator allows the programmer to specify how JavaScript moves through a for loop. true or false

true

Comments improve maintainability and help prevent bugs. - true - false

true

Functions are executed by writing a JavaScript expression with the name of the function followed by () which holds the parameters if there are any defined. -true -false

true

Functions are helpful to break up long programs into logical functionality -true -false

true

Global scope variables can be assigned a value inside a function. When other functions accesses the global variable, the value will be the same. -true -false

true

Global variables and local variables can be declared with the same name. If you are inside a function with a variable named the same as a global function, the local variable will be accessible and will "hide" the global variable. -true -false

true

Higher-order functions operate on other functions. true or false

true

I want to stop looping when a condition is met. However, I don't know how many times the loop will need to execute to meet that condition. A while loop will be able to provide the solution. -true -false

true

If I know I want to execute a block of code 4 times, a for loop will be able to provide a solution. -true -false

true

Which variable has local scope? var xPos = 200; var drawFlea = function () { var yPos = 200; fill(97, 93, 93); ellipse(xPos,yPos,20,10); fill(255,255,255); ellipse(xPos,yPos-10,10,15); ellipse(xPos+5,yPos-10,10,15); } -drawFlea -xPos -yPos -function

yPos


Set pelajaran terkait

ch. 7: reimbursement methodologies

View Set

Postassessment insurance guaranty Association

View Set

The Marketing Mix: Product, Place, Promotion, and Price

View Set

Module 6: Safety and Infection Control

View Set