function questions
function questions
o D) A type of loop
o D) To define variables
o A) on start
o B) func on
o C) set variable
o D) if-else
o C) To create a loop
o D) To define a variable
o A) movePlayer
o B) 123func on
o C) func on#1
o D) move Player
Func on Parameters
o C) Outputs of a func on
o A) Only 1
o B) Up to 5
o C) Unlimited
o A) func on movePlayer()
o B) func on movePlayer(speed)
o A) func on jump(height)
o C) func on a ack()
o D) func on setScore(score)
o B) func onName()
o A) Yes
o B) No
14. Which of the following is the correct way to call a func on with parameters?
makecode
Copy
func on sayHello() {
console.log("Hello!")
sayHello()
o A) "Hello!"
o B) "sayHello"
o C) No output
o D) Error
Return Values
o A) 0
o B) null
o C) undefined
o D) true
o A)
makecode
Copy
func on add(a, b) {
return a + b
o B)
makecode
Copy
func on greet() {
console.log("Hello!")
o C)
makecode
Copy
func on movePlayer() {
player.x += 1
}
o D)
makecode
Copy
func on setScore() {
score = 0
makecode
Copy
return a * b
mul ply(3, 4)
o A) 7
o B) 12
o C) 34
o D) 0
o A) Yes
o B) No
o C) To define a variable
o D) To create a loop
Advanced Concepts
o A)
makecode
Copy
func on countdown(n) {
if (n > 0) {
console.log(n)
countdown(n - 1)
o B)
makecode
Copy
func on movePlayer() {
player.x += 1
o C)
makecode
Copy
func on add(a, b) {
return a + b
}
o D)
makecode
Copy
func on setScore() {
score = 0
o D) To create a loop
o A) Global
o B) Local
25. What happens if you define a variable inside a func on without using let or const?
o C) It causes an error
o D) It is ignored
26. Why should you avoid using global variables inside func ons?
28. Which of the following is a good prac ce when naming func ons?
o D) To create errors
o A) func on abc()
o B) func on calculateScore()
o C) func on 123()
o D) func on doSomething#()
o C) A missing parameter
o D) A missing sprite
o C) To create a loop
o D) To define a variable
o C) Both A and B
35. What should you do if a func on is not returning the expected value?
o A)
makecode
Copy
sprite.x += speed
}
o B)
makecode
Copy
func on setScore() {
score = 0
o C)
makecode
Copy
func on greet() {
console.log("Hello!")
o D)
makecode
Copy
func on add(a, b) {
return a + b
o B) To create graphics
o C) To define variables
38. Which of the following func ons can be used to detect collisions?
o B) func on movePlayer()
o C) func on setScore()
o D) func on greet()
o B) To create sprites
o C) To define variables
40. Which of the following is an example of a func on used to reset the game?
o A)
makecode
Copy
func on resetGame() {
score = 0
player.x = 0
o B)
makecode
Copy
func on movePlayer() {
player.x += 1
o C)
makecode
Copy
func on greet() {
console.log("Hello!")
o D)
makecode
Copy
func on add(a, b) {
return a + b
Func on Challenges
makecode
Copy
func on square(n) {
return n * n
console.log(square(5))
o A) 10
o B) 25
o C) 5
o D) 0
makecode
Copy
func on add(a, b) {
return a + b
console.log(add(3, 7))
o A) 10
o B) 37
o C) 21
o D) 0
43. What is the output of the following code?
makecode
Copy
func on greet(name) {
console.log(greet("Alice"))
o A) Hello, Alice
o B) Hello, name
o C) Alice
o D) Error
makecode
Copy
func on isEven(n) {
return n % 2 == 0
console.log(isEven(4))
o A) true
o B) false
o C) 4
o D) 0
makecode
Copy
func on factorial(n) {
if (n == 0) return 1
return n * factorial(n - 1)
}
console.log(factorial(3))
o A) 6
o B) 3
o C) 1
o D) 0
Func on Design
46. Which of the following is a good prac ce when designing func ons?
47. What is the purpose of breaking code into mul ple func ons?
o A)
makecode
Copy
o B)
makecode
Copy
func on doEverything() {
o C)
makecode
Copy
func on setScore() {
score = 0
o D)
makecode
Copy
func on greet() {
console.log("Hello!")
o C) To hide errors
50. Which of the following is a good prac ce when tes ng func ons?
o D) Skip tes ng