Weeks 10 - 12
2nd Quiz : Monday, April 24.
Form elements review
Conditionals:
Here's a place to try things out.
Loops:
Make it so that your script determines when the puzzle has been solved. That is: whenever the picture is reassembled by the user (that is, all seven pieces are adjacent to one another in the "proper" order (the order they were occupied in your original picture) then:
Here are some of the things I'll talk about in class:
swap to red -- annotated example that shows how the first swap works to swap contents of last position with any image clicked upon
copycopy -- simple concatenation (may help to explain simple loop example here)
Issues:
<img src="pic7.jpg" onclick="f(7)">
function f(x){document.images[x].src="new.jpg"}
See strategies, below.
while (i++<numberofimages){document.images[i].src="new.jpg"}
a.
document.images[1].src="pic5.jpg";
document.images[2].src="pic3.jpg";
document.images[3].src="pic6.jpg";
etc.
or
b.
A=new Array(5,3,6,2,1,7,4);
while (i++<numberofimages){document.images[i].src="pic"+A[i]+"jpg"}
1. Load images in "solved" order first then determine resolved file addresses (see for example here)
2. Use string manipulation to pull off only the relevant characters
3. Remember which image is where through an array
New stuff for coming weeks:
random numbers, (teleology, mechanism and pragmatism) and evaluating a random number generator