hw06_28.html 1009 B

123456789101112131415161718192021222324252627282930
  1. <header>
  2. <h1>For Brackets Hell Check</h1>
  3. </header>
  4. <body>
  5. <script>
  6. const line = prompt();
  7. const bracketsStack = [];
  8. const openBrackets = ["[", "(", "{"];
  9. const closeBrackets = ["]", ")", "}"];
  10. let i = 0;
  11. for (let character of line) {
  12. //не обращайте внимания на символы, кроме трех видов скобок
  13. if (openBrackets.includes(character))
  14. bracketsStack.push(character);
  15. else {
  16. idx = closeBrackets.indexOf(character);
  17. if (idx >= 0) {
  18. if (bracketsStack.length == 0 || bracketsStack.pop() != openBrackets[idx]) {
  19. alert("Wrong brackets consistency in position: " + i)
  20. break; //оператор break прерывает цикл преждевременно
  21. }
  22. }
  23. }
  24. i++;
  25. }
  26. </script>
  27. </body>