Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML and Javascript, window.prompt
    primarykey
    data
    text
    <p>Very new to javascript and html-type stuff. I wanted to just make a quick example using input from a user and outputting it into a table. I'm having trouble getting the window prompt to actually come up though. I imagine there is somethign very obvious that I am doing wrong but I'm not currently seeing it...I am taking a class in school but this isn't a homework assignment, just exercises I am doing on my own.</p> <p>Is this something with the while loop? Any suggestions as to how I should keep prompting the user until they state otherwise? </p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Mileage Record&lt;/title&gt; &lt;style type = "text/css"&gt; table { width:300px; border-collapse:collapse; background-color:lightblue; } table, td, th { border: 1px solid black; padding: 4px; } th { text-align: left; color: white; background-color: darkblue } tr.oddrow { background-color: white; } &lt;/style&gt; &lt;script&gt; var milesDriven; var gallonsUsed; var mpg; var anyMore; document.writeln("&lt;table&gt;"); document.writeln("&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Miles Driven&lt;/th&gt;"); document.writeln("&lt;th&gt;Gallons Used&lt;/th&gt;"); document.writeln("&lt;th&gt;MPG&lt;/th&gt;"); document.writeln("&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;"); while (anyMore == true) { milesDriven = window.prompt("How many miles did you drive?"); gallonsUsed = window.prompt("How many gallons did you use?"); mpg = milesDrive/gallonsUsed; document.writln("&lt;tr&gt;&lt;td&gt;" + milesDriven + "&lt;/td&gt;&lt;td&gt;" + gallonsUsed + "&lt;/td&gt;&lt;td&gt;" + mpg + "&lt;/td&gt;&lt;/tr&gt;"); anymore = confirm("Do you have any more data to input?"); } document.writeln("&lt;/tbody&gt;&lt;/table&gt;"); &lt;/script&gt; </code></pre> <p><br> </p>
    singulars
    1. This table or related slice is empty.
    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. 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