In one word, what is a block of code that executes whenever you invoke its name?
Sorry, the answer is function.
Any name that is legal for a _________ is legal for a function.
Sorry, the answer is variable.
Write a function call that uses just 4 characters. Name it anything you like, within the limitation that the whole statement is just 4 characters.
Sorry, that's incorrect. An example of the correct code is:
f();
This is the first line of the function code. Write the statement that calls it.
function doSomething() {
Sorry, that's incorrect. The correct code is:
doSomething();
Drag and drop to assemble the first line of a function definition.
Click in the box and type the next character. I'll autocomplete. Don't type spaces.
Code the first line of a function displayAlert
The correct code is:
function displayAlert() {
Click in the box and type the next character. I'll autocomplete. Don't type spaces or carriage returns.
Code a function named askName that prompts the user to "Enter name" and assigns the answer to userName, which hasn't been declared beforehand.
The correct code is:
function askName() {
var userName = prompt("Enter name");
}
Code the first line of a function named for Johnny Appleseed's favorite fruit.
Sorry, that's incorrect. The correct code is:
function apple() {
Code a function named say that displays an alert with your first name as the message.
Sorry, that's incorrect. An example of the correct code is:
function say() {
alert("Mark");
}
Code a function that concatenates string1 and string2 and assigns the result to a variable that hasn't been declared beforehand. (For the sake of practice, I'm asking you to violate a good-coding rule here, which you'll learn about in Chapter 38. If you're charged with a coding crime, I'll testify to your innocence.)
Sorry, that's incorrect. An example of the correct code is:
function concat() {
var combo = string1 + string2;
}
What are the 4 missing characters, including a space?
function doSomething
Sorry, that's incorrect. The correct answer is:
() {
Code a function that calls itself.
Sorry, that's incorrect. An example of the correct code is:
function endless() {
endless();
}
Time goal: 20 seconds. This is the first line of the function code. Write the statement that calls it.
function doSomething() {
Sorry, that's incorrect. The correct code is:
doSomething();
Time goal: 50 seconds. Code a function that calls 2 other functions.
Sorry, that's incorrect. An example:
function callAFunction() {
doSomething();
doSomethingElse();
}
Time goal: 40 seconds. Click in the box and type the next character. I'll autocomplete. Don't type spaces or carriage returns.
Code a function named askName that prompts the user to "Enter name" and assigns the answer to userName, which hasn't been declared beforehand.
The correct code is:
function askName() {
var userName = prompt("Enter name");
}
Time goal: 45 seconds. Code a function named getName that displays a prompt that says "Enter name" and assigns the answer to userName, which hasn't been declared beforehand.
The correct code is:
function getName() {
var userName = prompt("Enter name");
}
Time goal: 45 seconds. Code a function that concatenates string1 and string2 and assigns the result to a variable that hasn't been declared beforehand.
An example of correct code is:
function putTogether() {
var mashup = string1 + string2;
}
Time goal: 45 seconds. Code a function that calls itself. (You wouldn't really want to do this. It would result in an endless loop.)
An example of correct code is:
function runsForever() {
runsForever();
}
Code a function that displays an alert, "Hello world." Call the function. If nothing happens, there is an error in your code.
Code a function that displays a prompt, "Enter name" and then displays the name in an alert. Call the function. If nothing happens, there is an error in your code.
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to jsFiddle. See my brief demo of jsFiddle.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19