Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:49:06+00:00 2026-05-26T04:49:06+00:00

I have this assignment to read, write, enable cookies so that the username will

  • 0

I have this assignment to read, write, enable cookies so that the username will be stored in a variable and then written into a cookie. My problem is that it seems like the last part of the code is working. But the first part where the username is suppose to be stored into the variable is not working, and I can see that when I run the code and the first two alert boxes don’t show. It is suppose to open with “Hello, I am your pet rock” And after I click iRock for the last time, the image is suppose to change to a happy iRock. But it doesn’t happen. I guess because the cookie didn’t get read. Any suggestions. Here is the link: http://ciswebs.smc.edu/cis54/tyson_schweidel /iRockChapter3.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org   /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>iRock - The Virtual Pet Rock</title>
<link href="donut_stylesheet/donut.css" rel="stylesheet" type="text/css" />

<script type ="text/javascript" >
var userName;

function resizeRock(){
document.getElementById("rockImg").style.height = (document.body.clientHeight - 100) * 0.9;
}

function greetUser(){
userName = readCookie("rock_username");
if(userName)
alert("Hello " + userName + ", I missed you.");
else 
alert("Hello, I am your pet rock");
}

function touchRock(){
if(userName)
    alert("I like attention," + userName + ". Thank you.");
}

    userName = prompt("What is your name?", "Enter name here.");
if(userName) 
alert("It is good to meet you, " + userName + ".");
writeCookie(irock_username", userName, 1 * 365);


document.getElementById("rockImg").src = "rock_happy.png";
setTimeout("document.getElementById(('rockImg').src = 'images/rock.png';", 5 * 60 * 1000);





</script>
</head>


<body onload="resizeRock(); greetUser(); onResize="resizeRock();">
<img id="rockImg" src="images/rock.png" alt="iRock" style="cursor:pointer"   onClick="touchRock();" />
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:49:07+00:00Added an answer on May 26, 2026 at 4:49 am

    Let’s break this down.

    How to enable cookies

    Cookies are enabled by default in pretty much every browser since at least 2000. While you can’t rely on someone having cookies enabled – I think it’s a safe assumption for a homework assignment. These days, for cookies to not be enabled, a user has to explicitly turn them off.

    read, write, enable cookies so that the username will be stored in a variable and then written into a cookie

    You have two functions that are undeclared. readCookie and writeCookie are being called, but you haven’t declared them anywhere yet. You need something that looks like this:

    function readCookie() {
        //Return the value of the cookie
    }
    
    
    function writeCookie(value) {
        //Write the value to the cookie
    }
    

    You can learn more about what exactly a cookie is here:

    http://www.quirksmode.org/js/cookies.html

    As well as how to read and write them.

    Additionally, you have a few syntax errors in your HTML and JavaScript. Make sure to review it carefully. Things to look for:

    • Make sure every curly brace ({}) has a matching opening / closing one.
    • Make sure all of the HTML attribute values are enclosed properly in quotes. For example, the onload attribute of your body seems to be missing a quote.

    Additional tips:

    Don’t try and build everything at once. Start off with one simple task, and get that working by itself. For instance, start with just setting / read the cookie and not worry about the rock. Once you get one feature working specifically the way you want it working, add more onto it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a method in my java assignment to write into a file
I obviously do not 'grok' C++. On this programming assignment, I have hit a
This is uni assignment and I have already done some stuff. Please go to
(this is indirectly a part of a much larger homework assignment) I have something
I have this code in jQuery, that I want to reimplement with the prototype
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
So the teacher has posed this assignment: You have been hired by the United
I have an assignment that I have to create a randomly sized 3D array,
This is a homework assignment, just for all that want to know. I'm writing
The program that I am writing needs to do this: read every line of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.