Image attached shows how to call doubleNumber(x) inside doubleBtn click event function. Implement sumBtn event function with sum(num1, num2) calls inside your code.
Question 10
10.
Question 11
11.
Question 12
12.
Question 13
13.
What happens if you try to print a function call when the function doesn't have a return value?
console.log( printNumbers(13,15,17));
console.log ( sum(13,15,17) );
Question 14
14.
Code along with the video3 and revise the function doubleNumber to return a value.( video:2:15)
What happens if you try to call the function with a return value like below?
doubleNumber(6);
randomNumber(1,10);
Question 15
15.
Question 16
16.
List 3 things you have discovered today.
Why do we write functions?
I. Make our code easier to understand by giving a readable name to a group of instructions
II. Avoid writing repeated code
III. Make our code reusable
I only
II only
I and II
I, II, and III
When we put a variable between parenthesis, what is it called?
Parameter
Function
doubledX
In the following function printThreeTimes:
function printThreeTimes(word){
println(word);
println(word);
println(word);
}
What is the parameter of the function?
word
println
function
On which line is the "call" to the function doubleNumber on the video? (video: 4:50 )
1
2
5
6
What would I get if I called doubleNumber(10); ? (video: 5:01 )
10
x
2x
20
After you watched all the video, Define the printNumbers function thattakes three integers and print them in given order
functionprintNumbers(two, one, zero){
println(two);
println(one);
println(zero);
}
Call printNumbers function whenever printNumberBtn is clicked (hint:onEvent("printNumberBtn", "click", function(){ call functions here } );
varzero =0;
varone=1;
vartwo= 2;
printNumbers(zero, one, two);
What will be displayed on the screen?
2
1
0
0
1
2
two
one
zero
two
zero
one
Revise the printNumbers function to print given parameters in below order.
functionprintNumbers(two, one, zero){
println(two);
println(zero);
println(zero);
println(one);
}
Revise the code inside printNumberBtn click event function as below.
printNumbers(12, 17, 65);
What will be displayed on the screen?
12
12
17
65
12
65
65
17
two
one
zero
two
zero
one
“It’s a bird! It’s a plane! No, it’s Superman!”
If it’s not a bird and it’s not a plane, it must be Superman.
We want to write a function isSuperman that takes in two boolean parameters isBird and isPlane and returns true if it is in fact Superman, not a bird and not a plane, and false otherwise.
Which of the following functions is the correct implementation of isSuperman?
True or False: Functions must have parameters.
True
False
How many parameters does the function sum use?
0
1
2
3
What would get printed if we added the code,
sum(4, 3); ?
4
3
7
Revise your doubleNumber() function to return value instead of printing it.
Replace all code inside doubleNumberBtn to below segment.
var numApples=4;
var twiceAsMany=doubleNumber(numApples);
println("Before : "+numApples);
println("After : "+twiceAsMany);
Will will be printed when this code is run?
Nothing will be printed
Before : 4
After :8
Revise doubleNumber(x) function and call it inside doubleNumberBtn as shown below.