These are chat archives for codebar/tutorials

17th
Jul 2015
Carolina Sawney
@assembly21
Jul 17 2015 11:09

Hi: I'm practising exercises from Head First Javascript Programming (p.101).

I write the code in the book in the console and it gives me an error: points is not defined. It's not necessary to define a variable points for the parameters, right? Thanks in advance.

var avatar = "generic";
var skill = 1.0;
var pointsPerLevel = 1000;
var userPoints = 2008;

function getAvatar(points){
var level = points / pointsPerLevel;
if (level == 1) {
return "Teddy bear";
} else if (level == 1) {
return "Cat";
} else if (level >= 2) {
return "Gorilla";
}
};
function updatePoints(bonus, newPoints) {
var i = 0;
while(i<points){
newPoints = newPoints + skill * bonus;
i = i + 1;
}
return newPoints + userPoints;
}
userPoints = updatePoints(2,100);
avatar = getAvatar(2112);

Ali
@Najaf
Jul 17 2015 12:11
It looks the problem is in your usage later in updatePoints
Where you're doing while (i < points)
points doesn't appear to be defined in the scope of updatePoints I mean.
Carolina Sawney
@assembly21
Jul 17 2015 12:17
the book has 6 tech reviewers...
Ali
@Najaf
Jul 17 2015 12:19
:P Who wants to spend their whole day reading code? Sounds way too much like work.