javascript - I want to have a dropdown menu where you choose the number instead of the variable -


the "var aantal = 10" gives me 10 traingles user insert own amount of triangles.

      var aantal = 10;          var triangle = [];        (var = 0; < aantal; i++){           triangle[i] = new triangle;           triangle[i].xleft = 20 + 30*i;           triangle[i].yleft = 20 + 20*i;        } 

a quick , easy way ask user input in browser via window.prompt method.

this stops code until user presses "ok" or "cancel" in popup window. when user fills in value , presses "ok", value returned string. here's example:

var userinput = prompt("how many triangles want?", 10);  var count = parseint(userinput, 10);    (var = 0; < count; += 1) {    console.log("triangle " + i);  }

note need explicitly convert string number. additionally, might want check null or nan: when user presses "cancel" or fills in invalid data, you'll need have fallback.

once works, might want try create <input type="number"> html element , data there.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -