// jshint esversion: 6
//1. Define a dispatcher to handle all button clicks
var main = function() {
//get values entered by the user
let str1 = document.getElementById("inBox1").value;
let str2 = document.getElementById("inBox2").value;
//the "this" keyword is set to the button that was clicked
//console.log(this.id);
//dispatch on button id
if (this.id == "b1") {
console.log("b1 clicked");
//display the concatenation of str1 and str2
document.querySelector("div").innerHTML = str1 + str2;
} else if (this.id == "b2") {
console.log("b2 clicked");
//display the concatenation of str1 and str2
document.querySelector("div").innerHTML =
str1.toLowerCase() + "_" + str2.toLowerCase();
}
};
//2. Register the onclick handler for each button after the DOM is complete
window.addEventListener("load", function() {
//select the buttons
var buttons = document.querySelectorAll("button");
//register the same handler for each button
for (var i = 0; i < buttons.length; ++i) {
buttons[i].addEventListener("click", main);
}
});