0
0
Javascriptprogramming~10 mins

Return values 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 return the sum of two numbers.

Javascript
function add(a, b) {
  return a [1] b;
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to use the return statement.
2fill in blank
medium

Complete the code to return the length of the string.

Javascript
function getLength(str) {
  return str[1];
}
Drag options to blanks, or click blank then click option'
A.length
B.size
C.length()
D.count
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using parentheses like a function call.
Using properties that don't exist like .size or .count.
3fill in blank
hard

Fix the error in the function to correctly return the square of a number.

Javascript
function square(num) {
  [1] num * num;
}
Drag options to blanks, or click blank then click option'
Aconsole.log
Bprint
Creturn
Doutput
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using console.log instead of return.
Not returning anything, so the function returns undefined.
4fill in blank
hard

Fill both blanks to create a function that returns true if a number is even.

Javascript
function isEven(num) {
  return num [1] 2 [2] 0;
}
Drag options to blanks, or click blank then click option'
A%
B==
C===
D!=
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using assignment = instead of comparison.
Using loose equality == instead of strict equality ===.
5fill in blank
hard

Fill both blanks to return an object with the uppercase key and its length as value for a given word.

Javascript
function wordInfo(word) {
  return { [1]: : [2] };
}
Drag options to blanks, or click blank then click option'
Aword.toUpperCase()
Bword.length
C*
D:
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using multiplication * instead of colon : in object.
Not calling toUpperCase() as a function.