Calculating the ratio... (to Javascript experts)
3 posters
Page 1 of 1
Calculating the ratio... (to Javascript experts)
I made something like this, but still does not work:
- Code:
$(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?
Ahmed.K- Forumember
- Posts : 349
Reputation : 4
Language : English
Re: Calculating the ratio... (to Javascript experts)
Hello friend, your code contains several errors!
Try this:
So long,
JS
Try this:
- Code:
jQuery(function () {
var given = Number(jQuery("#Thanks_given").text());
var received = Number(jQuery("#Thanks_received").text());
var ratio = parseInt(given / received);
if (ratio < 1) {
jQuery(function () {
jQuery('#Thanks_received').after('<div style="background:#b71604;color: #ffffff;font-size: 10px;font-weight: 800;padding: 0 3px;display:inline;">High Ratio</div>');
});
});
});
So long,
JS
Re: Calculating the ratio... (to Javascript experts)
Hello JScript, still does not work. if you want a test account, you have a PM.
Ahmed.K- Forumember
- Posts : 349
Reputation : 4
Language : English
Re: Calculating the ratio... (to Javascript experts)
Ok, try this:
Result:
Note:
To find the ratio of the two numbers, just divide the smaller by the greater to find how one mounts in relation with the other.
Example: divide 10 by 20 as follows:
10/20 = 0.5. This number shows that the first number is as 0.5 to 1. Now to adjust the ratio one step further, divide 1/0.5.
You get: 2. So the ratio of 10 and 20 is 1:2.
Now, read this: http://www.wikihow.com/Determine-Ratios
So long,
JS
- Code:
jQuery(function () {
jQuery("#profilepage2 li label").remove();
jQuery("#profilepage3 li label").remove();
var given = Number(jQuery("#profilepage2 li").text());
var received = Number(jQuery("#profilepage3 li").text());
if( given == 0 ) given = 1;
if( received == 0 ) received = 1;
var ratio = given / received;
ratio = 1 / ratio;
if (ratio < 1) {
jQuery(function () {
jQuery('#Thanks_received').after('<div style="background:#b71604;color: #ffffff;font-size: 10px;font-weight: 800;padding: 0 3px;display:inline;">High Ratio</div>');
});
};
});
Result:
- Spoiler:
Note:
To find the ratio of the two numbers, just divide the smaller by the greater to find how one mounts in relation with the other.
Example: divide 10 by 20 as follows:
10/20 = 0.5. This number shows that the first number is as 0.5 to 1. Now to adjust the ratio one step further, divide 1/0.5.
You get: 2. So the ratio of 10 and 20 is 1:2.
Now, read this: http://www.wikihow.com/Determine-Ratios
So long,
JS
Re: Calculating the ratio... (to Javascript experts)
I use it now, and still does not work.
btw, I don't have these IDs (profilepage2 and profilepage3):
var given = Number(jQuery("#profilepage2 li").text());
var received = Number(jQuery("#profilepage3 li").text());
btw, I don't have these IDs (profilepage2 and profilepage3):
var given = Number(jQuery("#profilepage2 li").text());
var received = Number(jQuery("#profilepage3 li").text());
Ahmed.K- Forumember
- Posts : 349
Reputation : 4
Language : English
Re: Calculating the ratio... (to Javascript experts)
Are you sure you do not have?
See below:
So long,
JS
See below:
So long,
JS
Re: Calculating the ratio... (to Javascript experts)
It works fine now with this:
$(document).ajaxStop(function(){
but how i show the ratio result in div as a number? for example: Thanks Ratio: 0.14.
this code does not work:
var ratio = given / received;
var ratio = $('#ratio');
with: <div id="ratio"></div>
$(document).ajaxStop(function(){
but how i show the ratio result in div as a number? for example: Thanks Ratio: 0.14.
this code does not work:
var ratio = given / received;
var ratio = $('#ratio');
with: <div id="ratio"></div>
Ahmed.K- Forumember
- Posts : 349
Reputation : 4
Language : English
Re: Calculating the ratio... (to Javascript experts)
strange indeed, nobody knows how showing the ratio? No Javascript experts here?
Ahmed.K- Forumember
- Posts : 349
Reputation : 4
Language : English
Re: Calculating the ratio... (to Javascript experts)
So why so far no one answered him means that there are no experts in JavaScript?
Being an expert is one thing, another thing is to make you understand, this is quite different...
The code below works in my tests, test yourself:
So long,
JS
Being an expert is one thing, another thing is to make you understand, this is quite different...
The code below works in my tests, test yourself:
- Code:
jQuery(function () {
jQuery("#profilepage2 li label").remove();
jQuery("#profilepage3 li label").remove();
var given = Number(jQuery("#profilepage2 li").text());
var received = Number(jQuery("#profilepage3 li").text());
if( given == 0 ) given = 1;
if( received == 0 ) received = 1;
var ratio = given / received;
ratio = 1 / ratio;
jQuery('#Thanks_received').after('<div style="background:#b71604;color: #ffffff;font-size: 10px;font-weight: 800;padding: 0 3px;display:inline;">Thanks Ratio' + ratio + '</div>');
});
So long,
JS
Re: Calculating the ratio... (to Javascript experts)
JScript, no, from what i see in the topic here, I think the only expert in JavaScript is you.
I was just kidding.
Anyway,
The code give me very long number
like this: 0.042139624601231544
Is it possible making something like this:
var ratio = ((given / received)-0,12)*received;
for example:
Thanks given = 500
Thanks received = 7000
so, will be:
500 / 7000 = 0.0714
0.0714 - 0.12 = -0.048
-0.048 x 7000 = (-340) and this will be the final result.
By the way, is your forum in English?
I was just kidding.
Anyway,
The code give me very long number
like this: 0.042139624601231544
Is it possible making something like this:
var ratio = ((given / received)-0,12)*received;
for example:
Thanks given = 500
Thanks received = 7000
so, will be:
500 / 7000 = 0.0714
0.0714 - 0.12 = -0.048
-0.048 x 7000 = (-340) and this will be the final result.
By the way, is your forum in English?
Ahmed.K- Forumember
- Posts : 349
Reputation : 4
Language : English
Re: Calculating the ratio... (to Javascript experts)
Ahmed.K wrote:It works fine now with this:
$(document).ajaxStop(function(){
but how i show the ratio result in div as a number? for example: Thanks Ratio: 0.14.
this code does not work:
var ratio = given / received;
var ratio = $('#ratio');
with: <div id="ratio"></div>
First Reminder:Ahmed.K wrote:strange indeed, nobody knows how showing the ratio? No Javascript experts here?
Please don't double post. Your post need to be separated by 24 hours before bumping, replying or adding more information. Please use the edit button instead!
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Similar topics
» Calculating the ratio... (to Javascript experts)
» New BBCodes...for Javascript experts...
» Sound for the notifications system... for Javascript experts...
» Sound for the notifications system. for Javascript experts...
» vista and calculating time
» New BBCodes...for Javascript experts...
» Sound for the notifications system... for Javascript experts...
» Sound for the notifications system. for Javascript experts...
» vista and calculating time
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum