Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to increase the value of count by 1 using a unary operator.
Javascript
let count = 5; count[1]; console.log(count);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--' which decreases the value.
Using '+=' which is not a unary operator.
Using '-' which subtracts but is not unary increment.
✗ Incorrect
The unary increment operator
++ increases the value by 1.2fill in blank
mediumComplete the code to convert the string numStr to a number using a unary operator.
Javascript
let numStr = "42"; let num = [1]numStr; console.log(typeof num);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parseInt which is a function, not a unary operator.
Using Number which is a function, not a unary operator.
Using '-' which negates the number but does not convert string to number.
✗ Incorrect
The unary plus operator converts a string to a number.
3fill in blank
hardFix the error in the code by choosing the correct unary operator to negate the value of value.
Javascript
let value = 10; let negated = [1]value; console.log(negated);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '++' which increments the value.
Using '+' which does not change the sign.
Using '--' which decrements the value.
✗ Incorrect
The unary minus operator negates the value, turning 10 into -10.
4fill in blank
hardFill both blanks to create an object flags where keys are numbers and values are their negations using unary operators.
Javascript
const numbers = [1, 2, 3]; const flags = {}; for (const num of numbers) { flags[[1]] = [2]; } console.log(flags);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using number directly as key without converting to string.
Using multiplication instead of unary minus for negation.
Using 'num' as value which is not negated.
✗ Incorrect
Keys must be strings, so
num.toString() is used. Values are negated with unary minus -num.5fill in blank
hardFill both blanks to create a new array results where each element is the negation of the numeric conversion of strings in arr.
Javascript
const arr = ["5", "-3", "10"]; const results = arr.map(item => [1][2]item); console.log(results);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical NOT
! which converts to boolean.Not converting string to number before negation.
Placing operators incorrectly causing syntax errors.
✗ Incorrect
First, unary plus
+ converts string to number, then unary minus - negates it. The empty string '' is used to separate operators correctly.