Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to throw a new error with the message "Oops!".
Javascript
throw new [1]("Oops!");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'throw' as a type instead of a keyword.
Using 'Exception' which is not a built-in JavaScript error type.
Using 'Message' which is not an error type.
β Incorrect
In JavaScript, to throw an error you use the Error constructor with the message inside parentheses.
2fill in blank
mediumComplete the code to throw a TypeError with the message "Invalid type".
Javascript
throw new [1]("Invalid type");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using SyntaxError which is for syntax issues.
Using ReferenceError which is for undefined variables.
Using generic Error instead of TypeError.
β Incorrect
TypeError is a built-in JavaScript error type used to indicate a type mismatch.
3fill in blank
hardFix the error in the code to correctly throw a RangeError with message "Out of range".
Javascript
throw [1]("Out of range");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Omitting the 'new' keyword causes a TypeError.
Using just the error type without 'new' is incorrect.
Using generic Error instead of RangeError.
β Incorrect
To throw an error object, you must use the 'new' keyword before the error type.
4fill in blank
hardFill both blanks to throw a SyntaxError with message "Syntax is wrong".
Javascript
throw [1]([2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Not using 'new' before the error type.
Passing the message without quotes.
Using the error type without 'new'.
β Incorrect
You must use 'new' to create the error object and pass the message as a string in quotes.
5fill in blank
hardFill both blanks to throw a ReferenceError with message "Variable not found".
Javascript
throw [1]([2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Omitting 'new' keyword.
Passing message without quotes.
Using wrong error type.
β Incorrect
You create a new ReferenceError object with 'new', pass the message as a string, and the error type is ReferenceError.