Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>About your script:</strong></p> <p>The problem in the script above is that last if statement which does some operations followed by a return. You need a semi-colon after the operation.</p> <p>In the future, as good practice, make sure to put a semi-colon after <strong>every</strong> valid statement. That way this won't bother you.</p> <p>Think of each line as a thought, and curly braces as ways to "group" and "relate" thoughts together.</p> <p>The below is a full thought that says "give me a variable "i" and give it the value 1 + 2;</p> <pre><code>var i = 1 + 2; </code></pre> <p>The below is a full thought about a condition that says "If i is 3 then add 1 to i". The thought "add 1 to i" is its own thought, so it needs a semicolon. Since the curlybraces for the IF statement are special in that they don't need a semi-colon after their "full thought" as long as you put a "block" (which is what curlybraces really make) after it, to enclose the thought.</p> <p>This means the following is valid:</p> <pre><code>if( i == 3 ) { i = i + 1; } </code></pre> <p>The following is <strong>not</strong> valid because the semi-colon after the if ends the "thought" before the if knows what to do if i equals 3:</p> <pre><code>if( i == 3 ) ; { i = i + 1; } </code></pre> <p>For a basic JavaScript tutorial, check out <a href="http://www.w3schools.com/js/js_intro.asp" rel="nofollow noreferrer" title="W3C Schools Javascript Tutorial">W3Schools</a>.</p> <p><strong>"There must be a better way?"</strong></p> <p>Any time you find yourself doing a lot of string operations on decmials, it's a good idea to ask yourself "is there a better way to do this?".</p> <p>It looks like you're writing a function to round a number to the nearest hundredths while displaying two decimal points. There's a much easier way to do this. You can just round to the nearest hundredths and have javascript output the fixed point number.</p> <p>Example:</p> <pre><code>function roundAmount( theDecimal ) { //first round to the nearest hundredth //then return the value with two decimal places as a string return theDecimal.toFixed( 2 ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload