Java Reference
In-Depth Information
}
for (i = 0; i < targets.length; i++) {
targets[i].addEventListener("dragover", handleOverDrop);
targets[i].addEventListener("drop", handleOverDrop);
targets[i].addEventListener("dragenter", handleDragEnterLeave);
targets[i].addEventListener("dragleave", handleDragEnterLeave);
}
</script>
</body>
</html>
Save this as ch12 _ question1.html .
This solution is rather simple. It introduces a new function called getRandomMessage() , which
returns one of three messages:
function getRandomMessage() {
var messages = [
"You moved an element!",
"Moved and element, you have! Mmmmmmm?",
"Element overboard!"
];
return messages[Math.floor((Math.random() * 3) + 0)];
}
And you use this function when you assign the message property to the data object in
handleDragStart() :
var data = {
elementId: this.id,
message: getRandomMessage()
};
Sadly, this solution still doesn't add much excitement to the example. But some is better than none, right?
Chapter 13
exercise 1 Question
Using local storage, create a page that keeps track of how many times the page has been visited by
the user in the last month.
exercise 1 Solution
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 13: Question 1</title>
</head>
Search WWH ::




Custom Search