Show list of numbers 1-10 multiplied by user entered number Objective of this program is to have the user enter 2 or 9 and output
the respective numbers multiple by 2 10 times.
Example if a user enters 2, browser will output the following:

2 times 2 is:4
3 times 2 is:6
⋮
11 times 2 is:22

I want like to know how can I simplify the underneath code? I have
placed the computation of the user entered value multiple by 2, on 2
separate" if else-if" statements. In case the user enters a wrong
number and subsequently when he enters the correct value, the values
wil be multipled by 2. See Loop A and Loop B comments to understand
what I mean.




let value = prompt("Enter Value between 2 or 9");

document.write(value);
document.write(`&lt;br&gt;`);

if (value == 2 || value == 9) {
//Loop A, when user enters 2 or 9, a list of its multiple by 2 is output to the user 10 
//times since I have already written the logic here how do I ensure it do not 
//write it again
 
  for (let i = 0; i &lt; 10; i++) {
    value2 = value * 2;
    document.write(`${value} times 2 is:${value2}`);
    document.write(`&lt;br&gt;`);
    //by adding "value++" the user entered value will increment
    value++;
  }
} else if (value &lt; 2 || value &gt; 9) {
  for (i = 0;(value &lt; 2 || value &gt; 9); i++) {
    value = prompt("Enter Value between 2 or 9");

    if (value == 2 || value == 9) {
    //Loop B, I want the computation to go to loop A instead of me having to write 
    //the computation of user value x 2
  //How can i accompolise this
      for (let i = 0; i &lt; 10; i++) {
        value2 = value * 2;
        document.write(`${value} times 2 is:${value2}`);
        document.write(`&lt;br&gt;`);
        //by adding "value++" the user entered value will increment
        value++;
      }
      break;
    }
  }
}
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
 &lt;meta content="text/html;charset=utf-8" http-equiv="Content-Type"&gt;
&lt;/head&gt;
&lt;body&gt;
 &lt;script type="text/javascript" src="myscript_multi_validation.js"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
Couple of things I noticed about your code.


Nothing happens if you enter any of the numbers 3,4,5,6,7,8 due to the else if statement checking for below 2 or above 9 instead of anything other than 2 or 9. To resolve this you should use an else instead of an else if as it will catch anything that is not 2 or 9 which is caught in the if statement.
You have created a manual infinite loop in your else if, the for loop will keep looping as long as the user enters a number below 2 or above 9 this is dangerous, if the number is not matched then it should reset the user back to a prompt and back to first if statement in theory.


How does the below catch your fancy?

let value = prompt("Enter Value between 2 or 9");

let loopAndOutput = function(value){
  if(value == 2 || value == 9){
    for(let i = 0; i &lt; 10; i++){
      console.log(`${i} times ${value} is:${value * i}`);
    }
  } else {
    let value = prompt("Enter Value between 2 or 9");
    loopAndOutput(value);
  }
}

loopAndOutput(value);