Question
For the following code below. When the user is prompted to ask for the 'size' I only want a numerical value to be accepted (example
For the following code below. When the user is prompted to ask for the 'size' I only want a numerical value to be accepted (example if the user enters "X" a pop-up will be shown saying invalid option, chose a number. '4' gets entered and the program continues down) I assume an If statement is needed but not entirely sure how to input that..
var size = prompt('Enter a size');
var inputA = prompt ('Enter favorite Animal'); var inputB = prompt ('Enter number value of how many you want'); var inputC = prompt ('Enter favorite color'); var art = [];
for (var x = 0; x < size; x++){ for (var y = 0; y < size; y++){ if ((x+y)%2 !=0 ){ art += inputA + ' ' ; }else{ art += inputB + ' '; } } art += inputC + ' '; } document.getElementById('myParagraph').innerHTML += ' ' + art;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started