Calculating the ratio... (to Javascript experts)
Posted February 2nd 2014, 7:48pm
There are 2 Divs: #Thanks_given li and #Thanks_received li.

But i want make this one; Thanks ratio (between the Thanks received and the Thanks given), with img bar and Css.

for example:

User:

Thanks given: 6000
Thanks received: 720
Thanks ratio: 0.2 (1200/6000=0.12) with img bar.


if the Thanks ratio= 0.12 the img bar= (full red bar) (Minimum ratio). with CSS.
if the Thanks ratio= 0.2 the img bar= IMG.
if the Thanks ratio= 0.3 the img bar= IMG.
if the Thanks ratio= 0.4 the img bar= IMG.
if the Thanks ratio= 0.5 the img bar= IMG.
if the Thanks ratio= 0.6 the img bar= IMG.
if the Thanks ratio= 0.7 the img bar= IMG.
if the Thanks ratio= 0.8 the img bar= IMG.
if the Thanks ratio= 0.9 the img bar= IMG.
if the Thanks ratio= 1.0 (and more) the img bar= (full green bar).
φ
Posts: 63
Joined: November 7th 2011, 12:00am
Likes Received: 4
Calculating the ratio... (to Javascript experts)
Posted February 3rd 2014, 1:28pm
Here's something to get you started:

var ratio = received / given;
var img_src = '(URL of full red image)';
if (ratio >= 0.2) {
img_src = '(URL of 0.2 image)';
}
elseif (ratio >= 0.3) {
img_src = '(URL of 0.3 image)';
}
elseif (ratio >= 0.4) {
img_src = '(URL of 0.4 image)';
}
elseif (ratio >= 0.5) {
img_src = '(URL of 0.5 image)';
}
elseif (ratio >= 0.6) {
img_src = '(URL of 0.6 image)';
}
elseif (ratio >= 0.7) {
img_src = '(URL of 0.7 image)';
}
elseif (ratio >= 0.8) {
img_src = '(URL of 0.8 image)';
}
elseif (ratio >= 0.9) {
img_src = '(URL of 0.9 image)';
}
else {
img_src = '(URL of full green image)';
}
(now use the img_src variable to display the image)

I'm sure there are better ways to accomplish this, but this is the easiest, and the easiest to understand.
φ
Posts: 1551
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 354
Calculating the ratio... (to Javascript experts)
Posted February 3rd 2014, 4:23pm
Good. but this to show the ratio, right? but how to Calculate the ratio and giving it id?
φ
Posts: 63
Joined: November 7th 2011, 12:00am
Likes Received: 4
Calculating the ratio... (to Javascript experts)
Posted February 26th 2014, 10:49am
Well, I made something, but still does not work:

$(document).ready(function(){
var given = $("#Thanks_given");
var received = $("#Thanks_received");
var ratio = given / received;
if (ratio < 1) {
$(function() {
$('#Thanks_received').after('<div style="background:#b71604;color: #ffffff;font-size: 10px;font-weight: 800;padding: 0 3px;display:inline;">High Ratio</div>');
});
});
}
});


any ideas why this does not work?
φ
Posts: 63
Joined: November 7th 2011, 12:00am
Likes Received: 4

Who is online

Users browsing this forum: No registered users and 0 guests