Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    -18x<sup>2</sup>
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    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...

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Code:
    var str = "-18x"
    var exponent = "2";
    var x = str + exponent.sup();
    document.write(x);

    “The expert at anything was once a beginner”

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    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

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Kiefer View Post
    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.
    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>

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,512
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •