Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-15-2012, 03:28 PM   PM User | #1
Kiefer
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Kiefer is an unknown quantity at this point
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.
Kiefer is offline   Reply With Quote
Old 10-15-2012, 03:31 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Code:
-18x<sup>2</sup>
?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 10-15-2012, 03:55 PM   PM User | #3
Kiefer
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Kiefer is an unknown quantity at this point
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...
Kiefer is offline   Reply With Quote
Old 10-15-2012, 04:19 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 10-15-2012, 04:34 PM   PM User | #5
Kiefer
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Kiefer is an unknown quantity at this point
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
Kiefer is offline   Reply With Quote
Old 10-15-2012, 09:43 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 10-15-2012, 10:00 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:14 PM.


Advertisement
Log in to turn off these ads.