Turning a number to superscript

Discussion in 'Javascript' started by dalei, Aug 23, 2005.

  1. dalei

    dalei Guest

    The following code does not work. Can anyone help with modifying it?

    <script type='text/javascript'>

    function super2 ()
    {
    var theNum = prompt ('Please enter a number: ', ' ');
    document.write ('Its superscript is: ' + <sup>theNum</sup>);
    }

    super2 ();
    </script>

    Thanks.
     
    dalei, Aug 23, 2005
    #1
    1. Advertising

  2. dalei

    Ivo Guest

    "dalei" wrote
    >
    > <script type='text/javascript'>
    >
    > function super2 ()
    > {
    > var theNum = prompt ('Please enter a number: ', ' ');
    > document.write ('Its superscript is: ' + <sup>theNum</sup>);
    > }
    >
    > super2 ();
    > </script>


    Did you mean
    document.write ( 'Its superscript is: <sup>' + theNum + '</sup>' );

    If not, let us know.
    hth
    ivo
     
    Ivo, Aug 23, 2005
    #2
    1. Advertising

  3. dalei

    dalei Guest

    It works. Thanks a lot.
     
    dalei, Aug 23, 2005
    #3
  4. dalei

    Robert Guest

    Ivo wrote:
    > "dalei" wrote
    >
    >><script type='text/javascript'>
    >>
    >>function super2 ()
    >>{
    >>var theNum = prompt ('Please enter a number: ', ' ');
    >>document.write ('Its superscript is: ' + <sup>theNum</sup>);
    >>}
    >>
    >>super2 ();
    >></script>

    >
    >
    > Did you mean
    > document.write ( 'Its superscript is: <sup>' + theNum + '</sup>' );


    Or this

    document.write ('Its superscript is: ' + theNum.sup());
     
    Robert, Aug 23, 2005
    #4
  5. dalei

    dalei Guest

    Wondering why this does not work. It would be more preferred for
    simplicity.
     
    dalei, Aug 25, 2005
    #5
  6. dalei

    Robi Guest

    dalei wrote in message news:...
    > Wondering why this does not work. It would be more preferred for
    > simplicity.


    since when does "turning a number to superscript" not work?

    or did you forget to quote what you're replying to?

    whazzup?
     
    Robi, Aug 25, 2005
    #6
  7. dalei

    dalei Guest

    Sorry. I referred following code:

    document.write ('Its superscript is: ' + theNum.sup());
     
    dalei, Aug 27, 2005
    #7
  8. dalei

    Lee Guest

    dalei said:
    >
    >Sorry. I referred following code:
    >
    >document.write ('Its superscript is: ' + theNum.sup());
    >

    Ok, and now what was that a reference to?

    Notice that everybody who has responded to you has included enough
    of the previous post to be able to understand what they are talking
    about, without having to trace back through old posts, which may
    have already expired from the system.
     
    Lee, Aug 27, 2005
    #8
  9. dalei

    Robert Guest

    >>> The following code does not work. Can anyone help with modifying it?

    >>> <script type='text/javascript'>


    >>> function super2 ()
    >>> {
    >>> var theNum = prompt ('Please enter a number: ', ' ');
    >>> document.write ('Its superscript is: ' + <sup>theNum</sup>);
    >>> }


    >> document.write ('Its superscript is: ' + theNum.sup());


    > Wondering why this does not work.


    No idea why it would no work. It works fine for me. Which part does not
    work? The writing to a document or putting the sup tag around the string?

    Ohh hmm, maybe because it think it is a number? Didn't try that.
    What about:
    document.write ('Its superscript is: ' + theNum.toString().sup());
    or:
    var theNum = prompt('Please enter a number: ', ' ').toString();
    document.write ('Its superscript is: ' + theNum.sup());

    Anyway, just wanted to say that string objects have a sup method you
    might like to use.
     
    Robert, Aug 27, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amber
    Replies:
    0
    Views:
    462
    Amber
    Oct 7, 2003
  2. dalei
    Replies:
    5
    Views:
    9,928
    Neredbojias
    Aug 28, 2005
  3. jodleren
    Replies:
    12
    Views:
    1,619
    GTalbot
    Jan 4, 2008
  4. shahid

    subscript and superscript

    shahid, Feb 4, 2009, in forum: C++
    Replies:
    14
    Views:
    7,861
    James Kanze
    Feb 6, 2009
  5. MBS
    Replies:
    5
    Views:
    293
Loading...

Share This Page