0
0
Javascriptprogramming~10 mins

Call stack behavior in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to call the function named greet.

Javascript
function greet() {
  console.log('Hello!');
}

greet[1];
Drag options to blanks, or click blank then click option'
A()
B[]
C{}
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of parentheses.
Forgetting to add parentheses, so the function is not called.
2fill in blank
medium

Complete the code to log the value returned by the function add.

Javascript
function add(a, b) {
  return a + b;
}

console.log(add[1]);
Drag options to blanks, or click blank then click option'
A{2, 3}
B(2, 3)
C[2, 3]
D2, 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Passing arguments without parentheses.
3fill in blank
hard

Fix the error in the recursive function call to avoid infinite recursion.

Javascript
function countdown(n) {
  if (n <= 0) {
    console.log('Done');
    return;
  }
  console.log(n);
  countdown[1];
}
Drag options to blanks, or click blank then click option'
A(n - 1)
B(n + 1)
Cn - 1
Dn + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Calling with n + 1 causing infinite recursion.
Forgetting parentheses around the argument.
4fill in blank
hard

Fill both blanks to create a function that returns the sum of squares of numbers in an array.

Javascript
function sumSquares(arr) {
  return arr.reduce((acc, num) => acc [1] num[2] 2, 0);
}
Drag options to blanks, or click blank then click option'
A+
B*
C**
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of addition in reduce.
Using wrong operator for squaring.
5fill in blank
hard

Fill all three blanks to create a recursive function that calculates factorial of n.

Javascript
function factorial([1]) {
  if ([2] <= 1) {
    return 1;
  }
  return [3] * factorial(n - 1);
}
Drag options to blanks, or click blank then click option'
An
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing errors.
Missing base case or wrong condition.