0

I'm building a website but a JavaScript part doesn't work. Look here the script:

    do {
      if (percen === 0) {
        console.log();
      } else if (percen === 1) {
        document.getElementById("percen").innerHTML = "Text"
      } else if (percen === 2) {
        document.getElementById("percen").innerHTML = "Text"
      } else if (clicks === 3) {
        ++percen;
      } else if (clicks === 4) {
        ++percen;
      } else if (clicks === 5) {
        ++percen;
      } else if (clicks === 6) {
        ++percen;
      } else if (clicks === 7) {
        var percen = 0;
      }
    }

But when I run it in a HTML file it will not loop. The var "percen" will ++ when you use a button.

Gary
  • 13,303
  • 18
  • 49
  • 71
  • 10
    *"do while doesn't work"* - Where is the `while`? – nnnnnn Mar 12 '17 at 13:22
  • Also don't declare `percen` again (with `var percen = 0`). Do it only once before you start looping. – caisah Mar 12 '17 at 13:23
  • Your browser has a console where it tells you about syntax errors, please find it (it's sometimes after the F12 short-cut). There's absolutely no need to play the guess game. – Álvaro González Mar 12 '17 at 13:31

2 Answers2

3

Try adding the 'while' portion of the 'do while' loop at the end:

do {
    if (percen === 0) {
        console.log();
    }

    // rest of your code
    // ...
}
while (percen < 100);
Cyrille
  • 3,427
  • 1
  • 30
  • 32
0

You forgot the condition at the end.. It is while(condition) remember that the condition is checked at the end of the script so it will enter 1 time. If you want you can do a while syntax while(cond){yourscript}