The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Calculating the ratio... (to Javascript experts)

View previous topic View next topic Go down

Calculating the ratio... (to Javascript experts)

Post by Ahmed.K on February 27th 2014, 3:56 am


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

Back to top Go down

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

Post by JScript on February 27th 2014, 4:58 am

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
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

Post by Ahmed.K on February 27th 2014, 3:55 pm

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

Back to top Go down

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

Post by JScript on February 28th 2014, 1:28 am

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
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

Post by Ahmed.K on February 28th 2014, 1:37 am

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());

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

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

Post by JScript on February 28th 2014, 2:01 am

Are you sure you do not have?
See below:


So long,

JS

JScript
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

Post by Ahmed.K on February 28th 2014, 6:46 pm

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
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

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

Post by Ahmed.K on March 1st 2014, 5:20 am

strange indeed, nobody knows how showing the ratio? No Javascript experts here?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

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

Post by JScript on March 1st 2014, 5:32 am

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
Forumember

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

http://jscript.forumeiros.com/

Back to top Go down

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

Post by Ahmed.K on March 1st 2014, 6:03 am

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?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

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

Post by SLGray on March 1st 2014, 6:34 am

@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!


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


SLGray
Administrator
Administrator

Male Posts : 35667
Reputation : 2375
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


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