Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem seems quite simple to me. If that is really all your HTML, your only problem is you don't have the <code>output</code> div.</p> <p>You can solve this in some ways. Using pure JavaScript...</p> <pre><code>var output = document.createElement("div"); // Creates a &lt;div&gt; element output.innerHTML = "Your running total = " + count; document.body.appendChild(output); // Add the &lt;div&gt; to the end of the &lt;body&gt; </code></pre> <p>Another way is to put the <code>output</code> div in the HTML, this way you won't even need to change your script:</p> <pre><code>&lt;div id="output"&gt;&lt;/div&gt; </code></pre> <p>If you want the <code>output</code> not to be visible before the input, you can CSS it a little...</p> <pre><code>&lt;div id="output" style="display: none;"&gt;&lt;/div&gt; </code></pre> <p>And make it visible with Javascript whenever you want.</p> <pre><code>var output = document.getElementById('output'); output.style.display = 'block'; // or 'inline-block', or 'inline', etc. See what fits you better </code></pre> <p>As you're beginnning with Javascript, I'd recommend you start in the right path by reading on unobstrusive Javascript. I can update the answer with some unobstrusive JS if you want.</p> <p><strong>UPDATE</strong>: If you want to substitute the <code>button</code> <code>div</code> with the new <code>output</code> <code>div</code>, you can simply change the names from <code>output</code> to <code>button</code> / <code>buttoner</code> / <code>whatever you want</code>.</p> <p><strong>UPDATE 2</strong>: Seems like I didn't understand your question correctly. If you want to store the previous answer, you can do it in a variety of ways as well.</p> <p>One is to store the current answer in a hidden field. For example...</p> <pre><code>&lt;input type="hidden" id="prevAnswer" value="0" /&gt; </code></pre> <p>Then, in your Javascript, you can do it like this:</p> <pre><code>var prevAnswer = document.getElementById("prevAnswer") var prevAnswerValue = parseFloat(prevAnswer.value) || 0; output.innerHTML = "You previously said you eat " + prevAnswerValue + " meals a week but you have currently listed " + num1 + " Dinners, " + num2 + " Lunches and " + num3 + " Breakfasts. This totals " + count + " meals."; prevAnswer.value = count; </code></pre> <p>So you will always have the Previous Answer whenever you calculate a new one.</p>
    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. 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.
 

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