Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Seems like you have a serious issue of no formatting madness going on. You should properly indent and format your JavaScript and terminate each statement with a semicolon:</p> <pre><code>function formatresults() { var displaystring = ""; if (this.timesup == false) { // if target date/time not yet met displaystring = "&lt;div class='row'&gt;&lt;div class='col'&gt; " + arguments[0] + " &lt;/div&gt; &lt;div class='thincol'&gt;&amp;#149;&lt;/div&gt; &lt;div class='col'&gt; " + arguments[1] + " &lt;/div&gt; &lt;div class='thincol'&gt;&amp;#149;&lt;/div&gt;&lt;div class='col'&gt; " + arguments[2] + " &lt;/div&gt; &lt;div class='thincol'&gt;&amp;#149;&lt;/div&gt; &lt;div class='col'&gt; " + arguments[3] + " &lt;/div&gt; &lt;/div&gt;"; } else { displaystring = "CRAP"; window.location.href = "http://example.com/"; } return displaystring } </code></pre> <p>The above code should work just fine. Now I don't know why you would want to redirect the user after having set <code>displaystring</code>, since that will abort the current page execution, but nonetheless; the above code should work.</p> <p>As Ben Lee writes; you shouldn't be doing <code>window.location.href</code> changes in this function, but instead in the function invoking <code>formatresults()</code> so <code>formatresults()</code> only does what it says, which is to format the results. This is how I'd solve it:</p> <pre><code>function formatresults() { var result = { success : false, value : null }; if (this.timesup) { // if target date/time not yet met result.success = false; result.value = "Time's up!"; } else { result.success = true; result.value = "&lt;div class='row'&gt;&lt;div class='col'&gt; " + arguments[0] + " &lt;/div&gt; &lt;div class='thincol'&gt;&amp;#149;&lt;/div&gt; &lt;div class='col'&gt; " + arguments[1] + " &lt;/div&gt; &lt;div class='thincol'&gt;&amp;#149;&lt;/div&gt;&lt;div class='col'&gt; " + arguments[2] + " &lt;/div&gt; &lt;div class='thincol'&gt;&amp;#149;&lt;/div&gt; &lt;div class='col'&gt; " + arguments[3] + " &lt;/div&gt; &lt;/div&gt;"; } return result; } // ... var result = formatresults(); if (!result.success) { window.location.href = "http://example.com/"; } else { // Do something with result.value } </code></pre>
 

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