,

Lab :

Except where otherwise noted, the contents of this document are Copyright © Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.

thanks to former TAs Victoria Kirst, Jeff Prouty, Morgan Doocy, Brian Le for their work on these labs.

Valid HTML5 Valid CSS

Basic lab instructions

Today's lab

This lab practices unobtrusive JavaScript events and the Document Object Model (DOM). We'll write a page with a "maze" to navigate with the mouse. You will write maze.js to implement the maze behavior.

maze

Info about the maze

Download the file below (right-click, Save Target As...) to get started:

The difficulty is in having the dexterity to move the mouse through without touching any walls. When the mouse cursor touches a wall, all walls turn red and a "You lose" message shows. Touching the Start button with the mouse removes the red coloring from the walls.

The maze walls are 5 div elements. Our provided CSS puts the divs into their proper places.

<div id="maze">
    <div id="start">S</div>
    <div class="boundary" id="boundary1"></div>
    <div class="boundary"></div>
    <div class="boundary"></div>
    <div class="boundary"></div>
    <div class="boundary"></div>
    <div id="end">E</div>
</div>

Exercise : Single boundary turns red (~15 min)

expected output

Write code so that when the user moves the mouse onto a single one of the maze's walls (onmouseover), that wall will turn red. Use the top-left wall; it is easier because it has an id of boundary1.

Exercise : All boundaries glow red on hover (~10 min)

Make it so that all maze walls turn red when the mouse enters any one of them.

expected output

Exercise : Alert on completion of maze (~10 min)

Make it so that if the user reaches the end of the maze, a "You win!" alert message appears.

expected output expected output

Exercise : Restartable maze (~10 min)

Make it so that when the user clicks the mouse on the Start square (a div with an id of start), the maze state will reset. That is, if the maze boundary walls are red, they will all return to their normal color, so that the user can try to get through the maze again.

expected output expected output

Exercise : JSLint / Upload Page (~5 min)

expected output

Exercise : On-page status updates (~10 min)

Instead of an alert, make the "You win" and "You lose" messages appear in the page itself.

expected output

Exercise : (h4x0rz only) Disallow cheating

It's too easy to cheat: Just move your mouse around the outside of the maze!

expected output

Exercise :(h4x0rz only) Fun Additional Features