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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
|
| 7 |
+
<title>Debug Buddy - Code Error Explainer</title>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
* {
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
margin: 0;
|
| 13 |
+
padding: 0;
|
| 14 |
+
font-family: Arial, sans-serif;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
body {
|
| 18 |
+
min-height: 100vh;
|
| 19 |
+
background: #f5f7fb;
|
| 20 |
+
color: #1f2937;
|
| 21 |
+
padding: 30px 15px;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.container {
|
| 25 |
+
width: 100%;
|
| 26 |
+
max-width: 900px;
|
| 27 |
+
margin: auto;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.header {
|
| 31 |
+
text-align: center;
|
| 32 |
+
margin-bottom: 25px;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.header h1 {
|
| 36 |
+
font-size: 36px;
|
| 37 |
+
margin-bottom: 10px;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.header p {
|
| 41 |
+
color: #6b7280;
|
| 42 |
+
font-size: 16px;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.card {
|
| 46 |
+
background: white;
|
| 47 |
+
border-radius: 16px;
|
| 48 |
+
padding: 25px;
|
| 49 |
+
margin-bottom: 20px;
|
| 50 |
+
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
label {
|
| 54 |
+
display: block;
|
| 55 |
+
font-weight: bold;
|
| 56 |
+
margin-bottom: 8px;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
select,
|
| 60 |
+
textarea {
|
| 61 |
+
width: 100%;
|
| 62 |
+
border: 1px solid #d1d5db;
|
| 63 |
+
border-radius: 10px;
|
| 64 |
+
padding: 12px;
|
| 65 |
+
font-size: 15px;
|
| 66 |
+
margin-bottom: 18px;
|
| 67 |
+
outline: none;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
select:focus,
|
| 71 |
+
textarea:focus {
|
| 72 |
+
border-color: #6366f1;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
textarea {
|
| 76 |
+
min-height: 150px;
|
| 77 |
+
resize: vertical;
|
| 78 |
+
font-family: Consolas, monospace;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
button {
|
| 82 |
+
width: 100%;
|
| 83 |
+
padding: 14px;
|
| 84 |
+
border: none;
|
| 85 |
+
border-radius: 10px;
|
| 86 |
+
background: #4f46e5;
|
| 87 |
+
color: white;
|
| 88 |
+
font-size: 16px;
|
| 89 |
+
font-weight: bold;
|
| 90 |
+
cursor: pointer;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
button:hover {
|
| 94 |
+
background: #4338ca;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.clear-btn {
|
| 98 |
+
margin-top: 10px;
|
| 99 |
+
background: #6b7280;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.clear-btn:hover {
|
| 103 |
+
background: #4b5563;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.result {
|
| 107 |
+
display: none;
|
| 108 |
+
margin-top: 20px;
|
| 109 |
+
padding: 20px;
|
| 110 |
+
border-radius: 12px;
|
| 111 |
+
background: #f8fafc;
|
| 112 |
+
border-left: 5px solid #4f46e5;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.result h2 {
|
| 116 |
+
margin-bottom: 15px;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.result-section {
|
| 120 |
+
margin-bottom: 18px;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.result-section h3 {
|
| 124 |
+
margin-bottom: 7px;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
pre {
|
| 128 |
+
background: #111827;
|
| 129 |
+
color: #e5e7eb;
|
| 130 |
+
padding: 15px;
|
| 131 |
+
border-radius: 10px;
|
| 132 |
+
overflow-x: auto;
|
| 133 |
+
white-space: pre-wrap;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.footer {
|
| 137 |
+
text-align: center;
|
| 138 |
+
color: #6b7280;
|
| 139 |
+
font-size: 13px;
|
| 140 |
+
margin-top: 20px;
|
| 141 |
+
}
|
| 142 |
+
</style>
|
| 143 |
+
</head>
|
| 144 |
+
|
| 145 |
+
<body>
|
| 146 |
+
|
| 147 |
+
<div class="container">
|
| 148 |
+
|
| 149 |
+
<div class="header">
|
| 150 |
+
<h1>🐞 Debug Buddy</h1>
|
| 151 |
+
<p>Code Error Explainer for Beginners</p>
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
<div class="card">
|
| 155 |
+
|
| 156 |
+
<label for="language">Programming Language</label>
|
| 157 |
+
|
| 158 |
+
<select id="language">
|
| 159 |
+
<option value="Python">Python</option>
|
| 160 |
+
<option value="JavaScript">JavaScript</option>
|
| 161 |
+
<option value="Java">Java</option>
|
| 162 |
+
<option value="C">C</option>
|
| 163 |
+
<option value="C++">C++</option>
|
| 164 |
+
<option value="C#">C#</option>
|
| 165 |
+
<option value="HTML">HTML</option>
|
| 166 |
+
<option value="CSS">CSS</option>
|
| 167 |
+
</select>
|
| 168 |
+
|
| 169 |
+
<label for="code">Your Code</label>
|
| 170 |
+
|
| 171 |
+
<textarea
|
| 172 |
+
id="code"
|
| 173 |
+
placeholder="Paste your code here..."
|
| 174 |
+
></textarea>
|
| 175 |
+
|
| 176 |
+
<label for="error">Error Message</label>
|
| 177 |
+
|
| 178 |
+
<textarea
|
| 179 |
+
id="error"
|
| 180 |
+
placeholder="Paste your error message here..."
|
| 181 |
+
></textarea>
|
| 182 |
+
|
| 183 |
+
<button onclick="explainError()">
|
| 184 |
+
🔍 Explain Error
|
| 185 |
+
</button>
|
| 186 |
+
|
| 187 |
+
<button class="clear-btn" onclick="clearAll()">
|
| 188 |
+
🗑️ Clear
|
| 189 |
+
</button>
|
| 190 |
+
|
| 191 |
+
<div class="result" id="result">
|
| 192 |
+
|
| 193 |
+
<h2>🔎 Error Explanation</h2>
|
| 194 |
+
|
| 195 |
+
<div class="result-section">
|
| 196 |
+
<h3>🔴 Error</h3>
|
| 197 |
+
<p id="errorTitle"></p>
|
| 198 |
+
</div>
|
| 199 |
+
|
| 200 |
+
<div class="result-section">
|
| 201 |
+
<h3>📌 Why it happened</h3>
|
| 202 |
+
<p id="reason"></p>
|
| 203 |
+
</div>
|
| 204 |
+
|
| 205 |
+
<div class="result-section">
|
| 206 |
+
<h3>💡 Suggested Fix</h3>
|
| 207 |
+
<pre id="fix"></pre>
|
| 208 |
+
</div>
|
| 209 |
+
|
| 210 |
+
<div class="result-section">
|
| 211 |
+
<h3>🧠 Tip</h3>
|
| 212 |
+
<p id="tip"></p>
|
| 213 |
+
</div>
|
| 214 |
+
|
| 215 |
+
</div>
|
| 216 |
+
|
| 217 |
+
</div>
|
| 218 |
+
|
| 219 |
+
<div class="footer">
|
| 220 |
+
Debug Buddy • AI Code Error Explainer
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
</div>
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
<script>
|
| 227 |
+
|
| 228 |
+
function explainError() {
|
| 229 |
+
|
| 230 |
+
const language =
|
| 231 |
+
document.getElementById("language").value;
|
| 232 |
+
|
| 233 |
+
const code =
|
| 234 |
+
document.getElementById("code").value.trim();
|
| 235 |
+
|
| 236 |
+
const error =
|
| 237 |
+
document.getElementById("error").value.trim();
|
| 238 |
+
|
| 239 |
+
const result =
|
| 240 |
+
document.getElementById("result");
|
| 241 |
+
|
| 242 |
+
const errorTitle =
|
| 243 |
+
document.getElementById("errorTitle");
|
| 244 |
+
|
| 245 |
+
const reason =
|
| 246 |
+
document.getElementById("reason");
|
| 247 |
+
|
| 248 |
+
const fix =
|
| 249 |
+
document.getElementById("fix");
|
| 250 |
+
|
| 251 |
+
const tip =
|
| 252 |
+
document.getElementById("tip");
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
if (!code && !error) {
|
| 256 |
+
alert("Please enter your code or error message.");
|
| 257 |
+
return;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
let title = "Unknown Error";
|
| 262 |
+
let explanation =
|
| 263 |
+
"The error could not be identified automatically.";
|
| 264 |
+
let suggestion =
|
| 265 |
+
"Check the error message and review your code.";
|
| 266 |
+
let advice =
|
| 267 |
+
"Read the error message carefully. It usually gives a clue about the problem.";
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
const errorText = error.toLowerCase();
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
if (
|
| 274 |
+
errorText.includes("syntaxerror") ||
|
| 275 |
+
errorText.includes("syntax error")
|
| 276 |
+
) {
|
| 277 |
+
|
| 278 |
+
title = "Syntax Error";
|
| 279 |
+
|
| 280 |
+
explanation =
|
| 281 |
+
"There is a problem with the structure or syntax of your code. Check brackets, quotes, commas, colons, and keywords.";
|
| 282 |
+
|
| 283 |
+
suggestion =
|
| 284 |
+
"Check your opening and closing brackets, quotes, commas, and the syntax required by " +
|
| 285 |
+
language +
|
| 286 |
+
".";
|
| 287 |
+
|
| 288 |
+
advice =
|
| 289 |
+
"Make sure every opening bracket or quote has the correct closing pair.";
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
else if (
|
| 294 |
+
errorText.includes("nameerror") ||
|
| 295 |
+
errorText.includes("not defined")
|
| 296 |
+
) {
|
| 297 |
+
|
| 298 |
+
title = "Name / Variable Error";
|
| 299 |
+
|
| 300 |
+
explanation =
|
| 301 |
+
"Your code is trying to use a variable, function, or name that has not been defined.";
|
| 302 |
+
|
| 303 |
+
suggestion =
|
| 304 |
+
"Check the spelling of the variable or function and make sure it is defined before you use it.";
|
| 305 |
+
|
| 306 |
+
advice =
|
| 307 |
+
"Variable names are often case-sensitive. Check spelling and capitalization.";
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
else if (
|
| 312 |
+
errorText.includes("typeerror")
|
| 313 |
+
) {
|
| 314 |
+
|
| 315 |
+
title = "Type Error";
|
| 316 |
+
|
| 317 |
+
explanation =
|
| 318 |
+
"Your code is trying to perform an operation using an incompatible data type.";
|
| 319 |
+
|
| 320 |
+
suggestion =
|
| 321 |
+
"Check the data types of the values involved and convert them when necessary.";
|
| 322 |
+
|
| 323 |
+
advice =
|
| 324 |
+
"Before performing an operation, make sure the values have compatible types.";
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
else if (
|
| 329 |
+
errorText.includes("indexerror") ||
|
| 330 |
+
errorText.includes("out of range")
|
| 331 |
+
) {
|
| 332 |
+
|
| 333 |
+
title = "Index Error";
|
| 334 |
+
|
| 335 |
+
explanation =
|
| 336 |
+
"Your code is trying to access an item at an index that does not exist.";
|
| 337 |
+
|
| 338 |
+
suggestion =
|
| 339 |
+
"Check the length of your list, array, or string before accessing an index.";
|
| 340 |
+
|
| 341 |
+
advice =
|
| 342 |
+
"Remember that many programming languages start counting indexes from 0.";
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
else if (
|
| 347 |
+
errorText.includes("indentationerror")
|
| 348 |
+
) {
|
| 349 |
+
|
| 350 |
+
title = "Indentation Error";
|
| 351 |
+
|
| 352 |
+
explanation =
|
| 353 |
+
"The indentation of your code is inconsistent or incorrect.";
|
| 354 |
+
|
| 355 |
+
suggestion =
|
| 356 |
+
"Check the spaces or tabs at the beginning of each line.";
|
| 357 |
+
|
| 358 |
+
advice =
|
| 359 |
+
"Use consistent indentation throughout your program.";
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
else if (
|
| 364 |
+
errorText.includes("referenceerror")
|
| 365 |
+
) {
|
| 366 |
+
|
| 367 |
+
title = "Reference Error";
|
| 368 |
+
|
| 369 |
+
explanation =
|
| 370 |
+
"JavaScript is trying to access a variable or object that does not exist in the current scope.";
|
| 371 |
+
|
| 372 |
+
suggestion =
|
| 373 |
+
"Check whether the variable is declared and whether its spelling is correct.";
|
| 374 |
+
|
| 375 |
+
advice =
|
| 376 |
+
"Make sure variables are declared before they are used.";
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
else if (
|
| 381 |
+
errorText.includes("nullpointerexception")
|
| 382 |
+
) {
|
| 383 |
+
|
| 384 |
+
title = "Null Pointer Exception";
|
| 385 |
+
|
| 386 |
+
explanation =
|
| 387 |
+
"Your program is trying to use an object that currently contains a null value.";
|
| 388 |
+
|
| 389 |
+
suggestion =
|
| 390 |
+
"Check whether the object is null before accessing its properties or methods.";
|
| 391 |
+
|
| 392 |
+
advice =
|
| 393 |
+
"Always verify that an object exists before using it.";
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
else if (
|
| 398 |
+
errorText.includes("modulenotfounderror") ||
|
| 399 |
+
errorText.includes("module not found")
|
| 400 |
+
) {
|
| 401 |
+
|
| 402 |
+
title = "Module Not Found";
|
| 403 |
+
|
| 404 |
+
explanation =
|
| 405 |
+
"The program cannot find the library or module that your code is trying to import.";
|
| 406 |
+
|
| 407 |
+
suggestion =
|
| 408 |
+
"Check the module name and make sure the required package is installed.";
|
| 409 |
+
|
| 410 |
+
advice =
|
| 411 |
+
"Verify the package name and your project's environment.";
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
result.style.display = "block";
|
| 416 |
+
|
| 417 |
+
errorTitle.textContent =
|
| 418 |
+
title + " (" + language + ")";
|
| 419 |
+
|
| 420 |
+
reason.textContent =
|
| 421 |
+
explanation;
|
| 422 |
+
|
| 423 |
+
fix.textContent =
|
| 424 |
+
suggestion;
|
| 425 |
+
|
| 426 |
+
tip.textContent =
|
| 427 |
+
advice;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
function clearAll() {
|
| 432 |
+
|
| 433 |
+
document.getElementById("code").value = "";
|
| 434 |
+
document.getElementById("error").value = "";
|
| 435 |
+
|
| 436 |
+
document.getElementById("result").style.display =
|
| 437 |
+
"none";
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
</script>
|
| 441 |
+
|
| 442 |
+
</body>
|
| 443 |
+
</html>
|