O'Reilly Forums: Exercise Not Working - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Exercise Not Working

#1 User is offline   mindapolis 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 20-December 11

Posted 31 January 2012 - 09:03 AM

hi I'm doing the exercise on page 26 but it 's not working. here 's the code. Can someone please help me?

<html>
<head>
<title>iRock - The Virtual Pet Rock</title>
<script type="text/javascript">
function touchRock() {
var userName = prompt("what 's your name?");

if (userName) {
alert("HOWDY," + userName + "?");
document.getElementById("rocking").src = "../assets/rock_happy.png";
}
}
</script>
</head>

<body onload="alert('hey, what 's up baby!');">
<div style="margin-top:100px; text-align:center">
<img id="rockImg" src="../assets/rock.png" alt="iRock" style="cursor:pointer" onclick-"touchRock();" />
</div>
</body>
</html>
0

#2 User is offline   lemuel 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 490
  • Joined: 13-April 09

Posted 31 January 2012 - 02:52 PM

if (userName) {
alert("HOWDY," + userName + "?");
document.getElementById("rocking").src = "../assets/rock_happy.png";
}

Your html doesn't have any elements with id="rocking". You do have one with id="rockImg".
0

#3 User is offline   mindapolis 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 20-December 11

Posted 31 January 2012 - 05:37 PM

I changed it but it still won't work.

<html>
<head>
<title>iRock - The Virtual Pet Rock</title>
<script type="text/javascript">
function touchRock() {
var userName = prompt("what is your name?");

if (userName) {
alert("want some," + userName + "?");
document.getElementById("rockImg").src = "../assets/rock_happy.png";
}
}
</script>
</head>

<body onload="alert('hey,');">
<div style="margin-top:100px; text-align:center">
<img id="rockImg" src="../assets/rock.png" alt="iRock" style="cursor:pointer" onclick-"touchRock();" />
</div>
</body>
</html>
0

#4 User is offline   lemuel 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 490
  • Joined: 13-April 09

Posted 31 January 2012 - 07:26 PM

See anything wrong with this?
onclick-"touchRock();"

0

#5 User is offline   mindapolis 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 20-December 11

Posted 01 February 2012 - 06:34 AM

I'm sorry in the book it looked like a dash not an equal sign. I changed it and now I'm getting the what 's your name part but I don't get a textbox to enter a name.
0

#6 User is offline   lemuel 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 490
  • Joined: 13-April 09

Posted 01 February 2012 - 09:55 AM

Your prompt box doesn't look like this?
Attached Image: Screenshot005.jpg
0

#7 User is offline   mindapolis 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 20-December 11

Posted 01 February 2012 - 11:04 AM

No, when the page first displays I get the rock image and the prompt asking for your name. after hitting ok I just get the image of the rock on the screen.
0

#8 User is offline   lemuel 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 490
  • Joined: 13-April 09

Posted 01 February 2012 - 11:34 AM

According to the code you posted, when the page loads you get an alert box that simply says "hey,". When you click on OK, you see the rock. You then click on the rock to get the prompt box.

If that is not happening then post your current code.
0

#9 User is offline   mindapolis 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 20-December 11

Posted 02 February 2012 - 07:32 PM

it 's working now. The book didn't make it clear that you were suppose to click on the rock the second time.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users