JavaScript/Control structures/Exercises

Topic: Conditional Branches

1. Write a script that allows a user to type in his name (prompt). The script shall answer depending on the length of the name.
 * Up to 5 characters: "Hello, . You have a short name."
 * Up to 10 characters: "Hello, . You have a name with a medium length."
 * Greater than 10 characters: "Hello, . Your name is very long."

2. Write a script that allows a user to type in a single character. The script shall decide whether it is a vocal ('a', 'e', 'i', 'o', 'u') or a consonant.
 * "You typed in the vocal: "
 * "You typed in the consonant: "
 * "You typed in a digit or some other character (+, -, *, ...): "

3. try / catch
 * Write a script that calls a function . This function does not exist in your script, which causes the JavaScript engine to generate a runtime error.
 * Catch the error and produce a meaningful error.
 * Terminate the script.

{What is the result?

+ A single message - Two messages
 * type=""}

{What shows the 'alert' statement? + 0 - 2 - 4 - None of the above
 * type=""}