These are chat archives for codefellows/sea-f1-TAs/Zach

15th
Sep 2014
Zach Bryan
@ZBryan
Sep 15 2014 02:25
for (i=0; i <=1; i++) {
    hamilton.speed = hamilton.trackCondition();
    rosberg.speed = rosberg.trackCondition();
    alonso.speed = alonso.trackCondition();
    vettel.speed = vettel.trackCondition();

  }
this loops is re assigning each time it runs
does this need to be a loop? or could you just do this assignment?
Ryan
@rraeburn
Sep 15 2014 02:31
Hey zach I'm having some issues when I'm trying to allow the user to input a racer and I'm not quite sure what I'm doing wrong
Zach Bryan
@ZBryan
Sep 15 2014 02:31
have a link to your code?
Ryan
@rraeburn
Sep 15 2014 02:32
yeah would it be easier for me to load it to github or post a screenshot?
Zach Bryan
@ZBryan
Sep 15 2014 03:00
it looks like you close your new animal instantiation function on line 23, then you use 'this' on line 25
Ryan
@rraeburn
Sep 15 2014 03:01
so should the userAnimal function be within the initial animal function?
Zach Bryan
@ZBryan
Sep 15 2014 03:01
what does 'this' refer to in this case?
Ryan
@rraeburn
Sep 15 2014 03:02
haha I honestly don't know this is what has been tripping me up. I'm trying to create something that would store user input into the correct category (i.e. speed, focus)
Zach Bryan
@ZBryan
Sep 15 2014 03:02
or make it var userAnimal
"this" in JS is confusing
what I would try....
var userAnimal = function () {
  alert ("An unknown racer has entered!");
  var userName = prompt("What is your name?");
  var userSpeed = prompt("How fast are you? 0-9");
  var userFocus = prompt("How focused are you? 0-9");
  var user = new Animal(userName, userSpeed, userFocus);
}
something like that
Ryan
@rraeburn
Sep 15 2014 03:07
wow that makes so much more sense
Zach Bryan
@ZBryan
Sep 15 2014 03:09
I didn't test, so you will need to make it work still
Ryan
@rraeburn
Sep 15 2014 03:10
So when I add this I keep getting the "user is not defined" reference error
Zach Bryan
@ZBryan
Sep 15 2014 03:11
how I you trying to use it
scope wise "user" only exists inside this function
Ryan
@rraeburn
Sep 15 2014 03:13
Screen Shot 2014-09-14 at 8.13.06 PM.png
Zach Bryan
@ZBryan
Sep 15 2014 03:14
three back tick ```
next line you code
three back ticks
that will give you semantic highlighting in gitter
Ryan
@rraeburn
Sep 15 2014 03:14
ah ok
Zach Bryan
@ZBryan
Sep 15 2014 03:19
okay so quick and dirty fix...
change the scopr of user
scope*
Ryan
@rraeburn
Sep 15 2014 03:22
so would this mean defining the "user" var outside of the userAnimal function to make it global?
Zach Bryan
@ZBryan
Sep 15 2014 03:22
yes
or just remove the function
function Animal (name, speed, focus) {
  this.name = name;
  this.speed = speed;
  this.focus = focus;
  this.position = 0;
  this.isFocused = function () {
    return Math.Floor(Math.random() * 10) < this.focus;
  }

  this.advance = function () {
    if (this.isFocused) {
      this.position += this.speed;
    }
  }

  this.progressReport = function () {
    return this.name + " is at" + this.position
  }

}

  alert ("An unknown racer has entered!");
  var userName = prompt("What is your name?");
  var userSpeed = prompt("How fast are you? 0-9");
  var userFocus = prompt("How focused are you? 0-9");
  var user = new Animal(userName, userSpeed, userFocus);

var rabbit = new Animal("Rocky", 8, 3);
var turtle = new Animal("Mrytle", 3, 7);
var meters = 100;

while (turtle.position < meters && rabbit.position < meters && user.position < meters) {
  rabbit.advance();
  turtle.advance();
  user.advance();
    alert(rabbit.progressReport() + "|" + turtle.progressReport() + "|" + user.progressReport());
}
not the best solution, but get it working then work on cleaning it up
Ryan
@rraeburn
Sep 15 2014 03:25
OK thanks I appreciate it. Not sure why I'm having such a rough time with this thing
Zach Bryan
@ZBryan
Sep 15 2014 03:32
sometimes the best thing you can do is walk away for a little while
Ryan
@rraeburn
Sep 15 2014 03:33
haha yeah I think that's probably not a bad idea
Zach Bryan
@ZBryan
Sep 15 2014 03:34
go for a run, read a book do something to disengage for 30 min then look at it again
Ryan
@rraeburn
Sep 15 2014 03:47
gonna do that. appreciate the help so far!
Zach Bryan
@ZBryan
Sep 15 2014 03:47
no problem, good luck