CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Exponent numeric display. (http://www.codingforums.com/showthread.php?t=277042)

Kiefer 10-15-2012 03:28 PM

Exponent numeric display.
 
Hello, I would like to apologize in advance for the somewhat weird english I'm going to write.

The problem is as follows, I need to make a program in javascript that creates a random monomial and then you have to solve it.

My isse is, how can I make the exponent look like the normal small number, for example:

This is how my exercise is shown: -18x2 when x is -54

I want it to show it like this: -18x˛ when x is -54


Any help would be greatly appreciated.

abduraooft 10-15-2012 03:31 PM

Code:

-18x<sup>2</sup>
?

Kiefer 10-15-2012 03:55 PM

Quote:

Originally Posted by abduraooft (Post 1280383)
Code:

-18x<sup>2</sup>
?

What I'm trying to use to convert is ("x" + Monomio.grado) where Monomio.grado is my exponent, but using <sup> or .sup doesnt appear to change anything.


Sorry for the rather stupid question...

Philip M 10-15-2012 04:19 PM

Code:

var str = "-18x"
var exponent = "2";
var x = str + exponent.sup();
document.write(x);


“The expert at anything was once a beginner”

Kiefer 10-15-2012 04:34 PM

Quote:

Originally Posted by Philip M (Post 1280397)
Code:

var str = "-18x"
var exponent = "2";
var x = str + exponent.sup();
document.write(x);


“The expert at anything was once a beginner”

If I use an associative array should it work like this?

(monomial.exponent).sup

Philip M 10-15-2012 09:43 PM

Quote:

Originally Posted by Kiefer (Post 1280401)
If I use an associative array should it work like this?

(monomial.exponent).sup

I do not have the faintest idea what your question is. But I do not see how associative arrays come into it. :confused:
sup() is an inbuilt Javascript method which is used to display a string as superscript text. My example shows how to apply that to the exponent (i.e. squared).

You can use the split() method to divide a number with exponent into its parts-

Code:

<script type = "text/javascript">

var string = "-18x12";  // minus 18 raised to the power of 12
var ssplit = string.split("x");
var str = ssplit[0] + "x";
var exponent = ssplit[1];
var x = str + exponent.sup();
document.write(x);

</script>


Old Pedant 10-15-2012 10:00 PM

I think he just misused terminology, Philip.

I think he has an object, referenced by the variable monomiial (or maybe Monomio--he uses different names in different posts) and that object has a property named exponent (or maybe grado--again, different names in different posts).

SO I think the answer is "yes".

I think if he simply uses monomial.exponent.sup() (or maybe it is Monomio.grado.sup()??) it will work.

It will not work as he showed it: (monomial.exponent).sup because he omitted the () after sup.


All times are GMT +1. The time now is 02:32 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.