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
Post a Comment