The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Calculating the ratio... (to Javascript experts)

3 posters

Go down

Calculating the ratio... (to Javascript experts) Empty Calculating the ratio... (to Javascript experts)

Post by Ahmed.K Wed 26 Feb 2014 - 21:56


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?
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by JScript Wed 26 Feb 2014 - 22:58

Hello friend, your code contains several errors!

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
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by Ahmed.K Thu 27 Feb 2014 - 9:55

Hello JScript, still does not work. if you want a test account, you have a PM.
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by JScript Thu 27 Feb 2014 - 19:28

Ok, try this:
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
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by Ahmed.K Thu 27 Feb 2014 - 19:37

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());
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by JScript Thu 27 Feb 2014 - 20:01

Are you sure you do not have?
See below:
Calculating the ratio... (to Javascript experts) Bdjdxw2

So long,

JS
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by Ahmed.K Fri 28 Feb 2014 - 12:46

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>
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by Ahmed.K Fri 28 Feb 2014 - 23:20

strange indeed, nobody knows how showing the ratio? No Javascript experts here?
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by JScript Fri 28 Feb 2014 - 23:32

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:
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
JScript
JScript
Forumember

Male Posts : 741
Reputation : 175
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by Ahmed.K Sat 1 Mar 2014 - 0:03

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?
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Calculating the ratio... (to Javascript experts) Empty Re: Calculating the ratio... (to Javascript experts)

Post by SLGray Sat 1 Mar 2014 - 0:34

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>

Ahmed.K wrote:strange indeed, nobody knows how showing the ratio? No Javascript experts here?
First Reminder:

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!


Calculating the ratio... (to Javascript experts) Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51489
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum