Hi, I'm new here on this forum and I have registered to receive help in certain situations and help others members if I can.
I start with a problem which gives me a headache, I created a prototype function that adds a multiple or submultiple metric string, works in if..if..if case but if I try to compact the code in a shorten way I get an error .
In this case 1e+5 => 100,000, with an alert: alert (1e+5) works perfectly, but when I try this code does not work at all:
Code:
var pw = 5;
alert (1e + (pw));
The complete code is at the end, I want to mention that the code below in comment (if...if...if) it works great but is very bad to read and to edit something, so I try to use a loop.
If anyone has a better solution please post it.
Thank you very much, I owe you one!
<script type = "text/javascript">
var pw = "5"; // a string value, not a number
var x = "1e" + pw; // concatenate strings
x = Number(x); // make a number
alert (x); // 100000
x = x.toExponential();
alert (x); // 1e+5
</script>
Quizmaster: A monocracy is a form of government in which how many people rule?
Contestant: Twelve.
__________________
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.
Number object do the trick, I did not thought about this solution (to convert to a number object), because the type of 1e+24 is treated as a number, but simply 1e does not mean anything.
Thank you for fast-reply and for explanations!
Great, but you should get rid of document.write() which is obsolete. Remember that any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it).
__________________
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.