Jump to content

Menu: Difference between revisions

700 bytes added ,  14 years ago
add JavaScript
(add JavaScript)
Line 185:
return ret;
}</lang>
 
=={{header|JavaScript}}==
{{works with|JScript}} for the I/O.
<lang javascript>function select(question, choices) {
var prompt = "";
for (var i in choices)
prompt += i + ". " + choices[i] + "\n";
prompt += question;
 
var input;
while (1) {
WScript.Echo(prompt);
input = parseInt( WScript.StdIn.readLine() );
if (0 <= input && input < choices.length)
break;
WScript.Echo("\nTry again.");
}
return input;
}
 
var choices = ['fee fie', 'huff and puff', 'mirror mirror', 'tick tock'];
var choice = select("Which is from the three pigs?", choices);
WScript.Echo("you selected: " + choice + " -> " + choices[choice]);</lang>
 
=={{header|OCaml}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.