we are building off a battleship game in github. Battleship
Here user, is prompted with his name and position of his ships and based on the answer, output is displayed on a textarea called domsole.
Domsole = (function($) {
var output;
var init = function(outname) {
output = $('#'+outname);
output.attr('disabled', 'disabled');
};
var ask = function(question) {
write(question);
var text = prompt(question);
write('> ' + text);
return text;
};
var write = function(text) {
output.append(text + "\n");
output.scrollTop(9999999999);
};
return {
ask: ask,
init: init,
write: write
};
})(jQuery);
$(document).ready(function() {
Domsole.init('domsole_out');
});
However, the all the prompts are asked before the page is loaded.
some of the prompts are
this.name = Domsole.ask("What's your name, Playa?");
Domsole.write("Alright, " + this.name + " you shall be.");
........
......
var coord = Domsole.ask("Where would you like to take a shot? Valid input is: x, y");
These code that calls Domsole.write and Domsole.ask are also in document.ready. Here all the prompts are asked before anything is displayed on the screen? How to resolve this issue?