-4

I have a doubt, I want to exit from program with conditional if, for example:

    var number = prompt("Choice a number between 1 and 6");
    var random = Math.floor(Math.random() * 6) + 1;
    if (parseInt(number) > 6){
        document.write("<p>Please, choice a number between 1 and 6</p>")
        // Here, I want to exit of conditional and program. 
    } else {
        if()
    }
    if() {
    } else {}

It´s possible.

Thank you very much

Alaon
  • 1
  • 2

2 Answers2

0

The main-thread of execution of the program belongs to the browser. JavaScript is invoked on demand; JavaScript code does not control the browser. So JavaScript code cannot exit the main thread of control or the browser. In your case, you can simply use return keyword. Remember that JS is a functional language, so your script ends when your function ends.

Prashant_M
  • 2,868
  • 1
  • 31
  • 24
0

Maybe you change the logic of the comparison

if (parseInt(number) <= 6) {
    // do other stuff
} else {
    document.write("<p>Please, choice a number between 1 and 6</p>")
    // Here, I want to exit of conditional and program. 
}
// this is the end of the program
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392