0% found this document useful (0 votes)
6 views

function questions

The document contains multiple-choice questions (MCQs) focused on functions in MakeCode Arcade, covering topics such as the definition and purpose of functions, parameters, calling functions, return values, advanced concepts, best practices, debugging, applications, challenges, and design principles. Each section includes questions that test knowledge on specific aspects of functions, such as their usage, naming conventions, and debugging techniques. The document serves as a comprehensive guide for understanding and applying functions within the MakeCode Arcade environment.

Uploaded by

chandan kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

function questions

The document contains multiple-choice questions (MCQs) focused on functions in MakeCode Arcade, covering topics such as the definition and purpose of functions, parameters, calling functions, return values, advanced concepts, best practices, debugging, applications, challenges, and design principles. Each section includes questions that test knowledge on specific aspects of functions, such as their usage, naming conventions, and debugging techniques. The document serves as a comprehensive guide for understanding and applying functions within the MakeCode Arcade environment.

Uploaded by

chandan kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

MCQs on Func ons in MakeCode Arcade

Basics of Func ons

1. What is a func on in MakeCode Arcade?

o A) A block of code that performs a specific task

o B) A variable that stores data

o C) A sprite in the game

o D) A type of loop

2. Why are func ons used in programming?

o A) To repeat code mul ple mes

o B) To organize code and avoid repe on

o C) To create game graphics

o D) To define variables

3. Which block is used to create a func on in MakeCode Arcade?

o A) on start

o B) func on

o C) set variable

o D) if-else

4. What is the purpose of the return statement in a func on?

o A) To stop the func on

o B) To send a value back to the caller

o C) To create a loop

o D) To define a variable

5. Which of the following is a valid func on name in MakeCode Arcade?

o A) movePlayer

o B) 123func on

o C) func on#1

o D) move Player
Func on Parameters

6. What are parameters in a func on?

o A) Variables that store data

o B) Inputs passed to a func on

o C) Outputs of a func on

o D) Loops inside a func on

7. How many parameters can a func on have in MakeCode Arcade?

o A) Only 1

o B) Up to 5

o C) Unlimited

o D) Depends on the func on

8. Which of the following is a valid func on with parameters?

o A) func on movePlayer()

o B) func on movePlayer(speed)

o C) func on movePlayer speed

o D) func on movePlayer = speed

9. What happens if you don’t pass a required parameter to a func on?

o A) The func on will not work

o B) The func on will use a default value

o C) The func on will return an error

o D) The func on will create a new parameter

10. Which of the following is an example of a func on with two parameters?

o A) func on jump(height)

o B) func on movePlayer(speed, direc on)

o C) func on a ack()

o D) func on setScore(score)

Calling Func ons


11. How do you call a func on in MakeCode Arcade?

o A) call func onName

o B) func onName()

o C) run func onName

o D) execute func onName

12. What happens when you call a func on?

o A) The func on code is executed

o B) The func on is deleted

o C) The func on is paused

o D) The func on returns a value automa cally

13. Can you call a func on inside another func on?

o A) Yes

o B) No

o C) Only if they have the same name

o D) Only if they have no parameters

14. Which of the following is the correct way to call a func on with parameters?

o A) movePlayer(5, "le ")

o B) movePlayer 5, "le "

o C) movePlayer = (5, "le ")

o D) call movePlayer with 5, "le "

15. What is the output of the following code?

makecode

Copy

func on sayHello() {

console.log("Hello!")

sayHello()

o A) "Hello!"
o B) "sayHello"

o C) No output

o D) Error

Return Values

16. What does a func on return if it has no return statement?

o A) 0

o B) null

o C) undefined

o D) true

17. Which of the following func ons returns a value?

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

18. What is the return value of the following func on?

makecode

Copy

func on mul ply(a, b) {

return a * b

mul ply(3, 4)

o A) 7

o B) 12

o C) 34

o D) 0

19. Can a func on return mul ple values?

o A) Yes

o B) No

o C) Only if they are numbers

o D) Only if they are strings

20. What is the purpose of the return statement?

o A) To stop the func on

o B) To send a value back to the caller

o C) To define a variable

o D) To create a loop
Advanced Concepts

21. What is a recursive func on?

o A) A func on that calls itself

o B) A func on with no parameters

o C) A func on that returns a value

o D) A func on that creates a sprite

22. Which of the following is an example of recursion?

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

23. What is the purpose of a local variable in a func on?

o A) To store data that can be used outside the func on

o B) To store data that can only be used inside the func on

o C) To define a global variable

o D) To create a loop

24. What is the scope of a variable defined inside a func on?

o A) Global

o B) Local

o C) Both global and local

o D) None of the above

25. What happens if you define a variable inside a func on without using let or const?

o A) It becomes a global variable

o B) It becomes a local variable

o C) It causes an error

o D) It is ignored

Func on Best Prac ces

26. Why should you avoid using global variables inside func ons?

o A) It can cause errors

o B) It makes the code harder to debug

o C) It reduces code readability


o D) All of the above

27. What is the benefit of using parameters in a func on?

o A) It makes the func on reusable

o B) It reduces the need for global variables

o C) It improves code organiza on

o D) All of the above

28. Which of the following is a good prac ce when naming func ons?

o A) Use descrip ve names

o B) Use short and unclear names

o C) Use numbers only

o D) Use special characters

29. What is the purpose of commen ng in func ons?

o A) To explain the code

o B) To make the code run faster

o C) To hide the code

o D) To create errors

30. Which of the following is an example of a well-named func on?

o A) func on abc()

o B) func on calculateScore()

o C) func on 123()

o D) func on doSomething#()

Debugging Func ons

31. What is the first step in debugging a func on?

o A) Check the func on logic

o B) Delete the func on

o C) Ignore the error

o D) Restart the program


32. What does a syntax error in a func on indicate?

o A) A mistake in the code structure

o B) A mistake in the logic

o C) A missing parameter

o D) A missing sprite

33. What is the purpose of console.log() in debugging?

o A) To print values to the console

o B) To stop the program

o C) To create a loop

o D) To define a variable

34. Which of the following is a common cause of errors in func ons?

o A) Missing return statement

o B) Incorrect parameter values

o C) Both A and B

o D) None of the above

35. What should you do if a func on is not returning the expected value?

o A) Check the logic and parameters

o B) Delete the func on

o C) Ignore the issue

o D) Restart the computer

Func on Applica ons

36. Which of the following is an example of a func on used to move a sprite?

o A)

makecode

Copy

func on moveSprite(sprite, speed) {

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

37. What is the purpose of a func on in a game loop?

o A) To update game state

o B) To create graphics

o C) To define variables

o D) To stop the game

38. Which of the following func ons can be used to detect collisions?

o A) func on checkCollision(sprite1, sprite2)

o B) func on movePlayer()

o C) func on setScore()
o D) func on greet()

39. What is the purpose of a func on in handling user input?

o A) To process keyboard or controller input

o B) To create sprites

o C) To define variables

o D) To stop the game

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

41. What is the output of the following code?

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

42. What is the output of the following code?

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) {

return "Hello, " + name

console.log(greet("Alice"))

o A) Hello, Alice

o B) Hello, name

o C) Alice

o D) Error

44. What is the output of the following code?

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

45. What is the output of the following code?

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?

o A) Keep func ons small and focused

o B) Use global variables extensively

o C) Avoid using parameters

o D) Write long and complex func ons

47. What is the purpose of breaking code into mul ple func ons?

o A) To improve readability and reusability

o B) To make the code harder to debug

o C) To increase the file size

o D) To create more errors

48. Which of the following is an example of a well-designed func on?

o A)

makecode

Copy

func on calculateArea(width, height) {

return width * height

o B)

makecode

Copy
func on doEverything() {

// 100 lines of code

o C)

makecode

Copy

func on setScore() {

score = 0

o D)

makecode

Copy

func on greet() {

console.log("Hello!")

49. What is the purpose of tes ng func ons?

o A) To ensure they work as expected

o B) To make the code run faster

o C) To hide errors

o D) To create more func ons

50. Which of the following is a good prac ce when tes ng func ons?

o A) Test with different input values

o B) Test only once

o C) Ignore edge cases

o D) Skip tes ng

You might also like