From e12810dd69c00e8a2cccb5e907d6e287b508f426 Mon Sep 17 00:00:00 2001 From: Nirzara Ghure <113231114+nirzaraghure@users.noreply.github.com> Date: Mon, 13 Apr 2026 18:22:52 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20AppGenius:=20AI-generated=20code?= =?UTF-8?q?=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/script.js b/script.js index 4bfed27..a4cda53 100644 --- a/script.js +++ b/script.js @@ -1,28 +1,25 @@ ```javascript -function generateQR() { - const inputElement = document.getElementById("text"); - const qrCodeDiv = document.getElementById("qrcode"); +// Get HTML elements +const inputElement = document.getElementById("text"); +const qrCodeDiv = document.getElementById("qrcode"); +const generateButton = document.getElementById("generateButton"); - if (inputElement.value.trim() === "") { +// Validate input and generate QR code on button click +generateButton.addEventListener("click", () => { + if (inputElement.value.trim() === '') { alert("Please enter text or URL"); return; } if (typeof inputElement.value !== "string") { - throw new Error("Input must be a string"); - } - - try { - const qrcode = new QRCode(qrCodeDiv, { - text: inputElement.value, - width: 200, - height: 200 - }); - } catch (error) { - console.error(error); - alert("An error occurred while generating the QR code"); + alert("Input must be a string"); + return; } -} -document.getElementById("generateButton").addEventListener("click", () => generateQR()); + const qrCode = new QRCode(qrCodeDiv, { + text: inputElement.value, + width: 200, + height: 200 + }); +}); ``` \ No newline at end of file