0

I am trying to have an adjustable height for separate columns based on different percentages compared to other users data.

function Person(name, points) {
    "use strict";
    this.name = name;
    this.points = points;
    this.height = 0;
}

var daniel = new Person('Daniel', '2');
var boaz = new Person('Boaz', '4');
var josh = new Person('josh', '5');

Person.prototype.getHeight = function () {
    "use strict";
    var scores = [daniel.height, boaz.height, josh.height],
        highest = 0,
        i = 0;
    for (i; i < scores.length; i += 1) {
        if (scores[i] > highest) {
            highest = scores[i];
        }
    }
    this.height = String(this.points / highest);
    return this.height;
};

$(document).ready(function () {
    "use strict";
    var $daniel = daniel.getHeight() + '%',
        $boaz = boaz.getHeigt() + '%',
        $josh = josh.getHeight + '%';
    $('#daniel').height($daniel);
    $('#boaz').height($boaz);
    $('#josh').height($josh);
});

basically all this code does is creates three different person with different point levels, and then sets their heights according to the percent value compared to the person with the highest score. E.G. I have ten points and you have three points, I would be 100 and you would be 3. I then use jQuery to convert this to % and try to resize the individual ids according to the percentage.

For some reason nothing is showing up when I do this on the actual page. What is going wrong? I am assuming that it has something to do with the jQuery, as the normal javascript is doing fine.

2 Answers 2

1
var scores = [daniel.height, boaz.height, josh.height],

should be

var scores = [daniel.points, boaz.points, josh.points],

Right?

And since you use %, so

this.height = String(this.points / highest);

should be

this.height = this.points / highest * 100;
Sign up to request clarification or add additional context in comments.

3 Comments

Wow thanks. Renamed some things and I guess I never changed that. Thanks! but it still didn't work haha
@bob And you have to * 100 for using %
Wait, this did fix it. Thank you so much! I'll need to look my code over closer next time...
1

You have a typo here:

$boaz = boaz.getHeigt() + '%'

which should be:

$boaz = boaz.getHeight() + '%'

1 Comment

Wow. messing up today. Thanks. But that still doesn't fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.