Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Chris Copley
    @chriscopley
    Thanks. I'm still not clear on those either, obviously.
    @dianapham I revised my page rebuild, BTW.
    Diana
    @dianapham
    okay paste it here. there's a little rectangular box with lines on the bottom right corner of the typing box. it'll show you shortcuts on how to add code to this chat
    Chris Copley
    @chriscopley
    Paste the race game? or the page rebuild?
    Diana
    @dianapham
    either. if the page rebuild is good, just resubmit it on canvas.
    Chris Copley
    @chriscopley

    OK. Here's the race game<script>
    // I want to create a game in which one competitor can eliminate another. In this case, a spaceship "race." Kind of like something from "Star Wars." But because I still don't know what I'm doing, I'm trying to build a stupidly simple race game to start with. But my code is not running
    function Spaceship(name, speed) {
    this.name = name;
    // Values 0 - 9 for speed
    this.speed = speed;
    this.position = 0;
    alert("successfully set params")

        }
        this.advance = function() {
            return this.position + this.speed;
            alert("successfully set advance")
            }
        }
        this.progressReport = function() {
            return this.name + " is at " + this.position
        }
    }
    var freighter = new Spaceship("Big Mac", 5, 4);
            alert("successfully set Big Mac")
    var battleship = new Spaceship("Warhorse", 2, 9);
            alert("successfully set Warhorse")
    var passengerLiner = new Spaceship("Space Duck", 7, 1);
            alert("successfully set Space Duck")
    var meters = 50;
        alert("successfully set meters")
    
    while ((freighter.position < meters && battleship.position < meters) && passengerLiner.position < meters) {
        freighter.advance();
        battleship.advance();
        passengerLiner.advance();
        alert(freighter.progressReport() + " | " + battleship.progressReport() + " | " passengerLiner.progressReport());
    }

    </script>

    Chris Copley
    @chriscopley
    Not sure why only some of the code appears as code.
    Diana
    @dianapham
    @chriscopley sorry for the delay. i've been sick in bed.
    right before you create "this.advance = function ....." you have a closing curly brace.
    that means you're closing the Spaceship
    all yoru other properties aren't part of Spaceship now
    Chris Copley
    @chriscopley
    Sorry you're not feeling well.
    I copied that part of the code from what Brook wrote, but then I modified it. Clumsily, apparently. OK, so I'll take out that bracket.
    Chris Copley
    @chriscopley
    The code still doesn't launch.
    Diana
    @dianapham
    when you're creating new spaceships, i notice you've got 3 values. in your initial spaceship constructor, you're only asking for two values.
    @chriscopley go ahead and grab one of the TAs in class right now since they'll be able to sit next to you and go over the code. sorry i couldn't be there.
    Chris Copley
    @chriscopley
    I did. I sat with Dale, I think. The older TA. He didn't know JS real well, but did help with syntax. Got the thing to run. But my spaceships don't advance. I don't know how to add this.position and this.speed. The + apparently doesn't do it. Or I need parens. Or something.
    Feeling better?
    Diana
    @dianapham

    @chriscopley i finally debugged your code. basically i had to rewrite the whole thing from scratch to see what the differences where.

    • all your added alerts needed semicolons.
    • you had a bunch of unnecessary closing brackets in the Spaceship function that wasn't allowing the other properties to be set
    • you needed "this.advance" to have "this.position += this.speed" the plus equal means you add speed to the position and then put that new value into position. so you're updating position. this is key. if you don't put the equal sign after position, you're basically just concatenating the two values and not doing math
    • you added 3 values when creating new Spaceships when the actually Spaceship constructor just required 2 values.
    • the very last alert where it shows the progressReports, you were missing a plus sign before the passengerLinger.progressReport()

    fix those things and let me know if it works. i've rewritten yours a few times just fixing those errors and it seems to work now. the += was what really caused the lack of advancement.

    and yeah, i'm feeling a little bit better. for some reason it's hard to breathe at night when i'm sick though so i basically just stay up and work. coding4life!
    Chris Copley
    @chriscopley
    @dianapham Glad you're better. And yes! I noticed the missing + when Dale and I went over the code last night. (Excellent! I noticed something wrong in JS!) I made the += change just now and the code works as intended. But, as I said, I had simplified it so I could get SOMETHING to work -- just two arguments for each class member (name, speed). So I made the remainder consistent with that, and now I need to build out the game to be something more.
    Diana
    @dianapham
    okay. those suggestions i made above are based off of the most recent code you posted in the above chat. if you've made other changes and we want me to look at them, feel free to post it here.
    Chris Copley
    @chriscopley
    @dianapham Thanks. I will.
    Emily Doherty
    @edohert
    Diana, will you be in lab tonight? If so will you be going over jquery? Hope you are feeling better!!
    Diana
    @dianapham

    yeah, i'm planning on being at lab tonight. and yes, i want to go over css and jquery. i'm waiting for brook to post the slides from yesterday so i can see what you guys went over. was there anything specific you wanted to review for jquery?

    (fyi. i'll probably smell like cough drops all night.)

    Emily Doherty
    @edohert
    There were no slides last night, he projected pages from the book and used the code examples provided online. At this point nothing specific. (and who doesn't like the smell of cherry menthal
    menthol*
    Diana
    @dianapham
    ahhhh. okay. i saw those examples. i'll sift through them and prepare something for later.
    Emily Doherty
    @edohert
    Gracias!
    Chris Copley
    @chriscopley
    @dianapham Not to overload you, but are you planning to be at Uptown Espresso at 4:30 ish?
    Diana
    @dianapham
    @chriscopley yeah probably. there seems to be traffic from the eastside, so i'm shooting for 4:45ish
    Chris Copley
    @chriscopley
    k
    Diana
    @dianapham
    @chriscopley i dunno why my other message didnt go through. im still stuck in traffic so i apologize if i dont arrive before you have to leave. hopefully there are others at uptown espresso that can help out
    Diana
    @dianapham
    i'm in the conference room
    Chris Copley
    @chriscopley
    @dianapham Will you or another TA be talking about something at the classroom early today?
    Diana
    @dianapham
    @chriscopley yeah i'm here now
    Emily Doherty
    @edohert
    @dianapham will you be at uptown espresso prior to lab tonight?
    Diana
    @dianapham
    yeah i'm here now