Objective of this program is to have the user enter 2 or 9 and outputthe respective numbers multiple by 2 10 times.Example if a user enters 2 browser will output the following:2 times 2 is:43 times 2 is:6.....11 times 2 is:22I want like to know how can I simplify the underneath code? I haveplaced the computation of the user entered value multiple by 2, on 2separate if else-if statements. In case the user enters a wrongnumber and subsequently when he enters the correct value, the valueswil be multipled by 2. See Loop A and Loop B comments to understandwhat I mean.let value = prompt(Enter Value between 2 or 9);document.write(value);document.write(`<br>`);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 < 10; i++) {    value2 = value * 2;    document.write(`${value} times 2 is:${value2}`);    document.write(`<br>`);    //by adding value++ the user entered value will increment    value++;  }} else if (value < 2 || value > 9) {  for (i = 0;(value < 2 || value > 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 < 10; i++) {        value2 = value * 2;        document.write(`${value} times 2 is:${value2}`);        document.write(`<br>`);        //by adding value++ the user entered value will increment        value++;      }      break;    }  }}<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN     http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd><html><head> <meta content=text/html;charset=utf-8 http-equiv=Content-Type></head><body> <script type=text/javascript src=myscript_multi_validation.js></script></body></html>
Javascript simplify code | to calculate the user value multiple by 2 as a single logic in one if statement instead of adding it in 2
javascript
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 < 10; i++){      console.log(`${i} times ${value} is:${value * i}`);    }  }}loopAndOutput(value);