Debug Delimiters!

List (as a Stack) Loop Conditional Statement

Problem Background

One of the most common and frustrating errors for new programmers (and even seasoned veterans!) is the Delimiter Mismatch. These errors occur when you open a parenthesis (, curly brace {, or square bracket [ but forget to close it, or worse, close a type that wasn't the last one opened. A single missing or misplaced delimiter can cause an entire program to fail compilation or execution, leading to hours of frustrating debugging. Learning to identify these errors is a critical skill, but automating this process can be a powerful tool in any developer's arsenal.

Problem Description

Your task is to write a JavaScript program that analyzes a string of code (or any string containing delimiters) and determines if the opening and closing characters—parentheses (), curly braces {}, and square brackets []—are correctly matched and balanced.

The code must adhere to two core rules for successful balancing:

The program should take a string of code as input and return a clear message indicating whether the string has Balanced or Unbalanced delimiters, along with the reason if it is unbalanced.

Examples

Sample Input

function example() { let x = [1, 2]; return true; }

Sample Output

Balanced

Sample Input

if (a == b)) { console.log(a); }

Sample Output

if (a == b)) : Extra )

Sample Input

while (true { doSomething(); }

Sample Output

Missing ')'