Codeerrorchecking / index.html
Jayaviji's picture
Final code error
97ba2d4 verified
Raw History Blame Contribute Delete
9.53 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Debug Buddy - Code Error Explainer</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
min-height: 100vh;
background: #f5f7fb;
color: #1f2937;
padding: 30px 15px;
}
.container {
width: 100%;
max-width: 900px;
margin: auto;
}
.header {
text-align: center;
margin-bottom: 25px;
}
.header h1 {
font-size: 36px;
margin-bottom: 10px;
}
.header p {
color: #6b7280;
font-size: 16px;
}
.card {
background: white;
border-radius: 16px;
padding: 25px;
margin-bottom: 20px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
}
label {
display: block;
font-weight: bold;
margin-bottom: 8px;
}
select,
textarea {
width: 100%;
border: 1px solid #d1d5db;
border-radius: 10px;
padding: 12px;
font-size: 15px;
margin-bottom: 18px;
outline: none;
}
select:focus,
textarea:focus {
border-color: #6366f1;
}
textarea {
min-height: 150px;
resize: vertical;
font-family: Consolas, monospace;
}
button {
width: 100%;
padding: 14px;
border: none;
border-radius: 10px;
background: #4f46e5;
color: white;
font-size: 16px;
font-weight: bold;
cursor: pointer;
}
button:hover {
background: #4338ca;
}
.clear-btn {
margin-top: 10px;
background: #6b7280;
}
.clear-btn:hover {
background: #4b5563;
}
.result {
display: none;
margin-top: 20px;
padding: 20px;
border-radius: 12px;
background: #f8fafc;
border-left: 5px solid #4f46e5;
}
.result h2 {
margin-bottom: 15px;
}
.result-section {
margin-bottom: 18px;
}
.result-section h3 {
margin-bottom: 7px;
}
pre {
background: #111827;
color: #e5e7eb;
padding: 15px;
border-radius: 10px;
overflow-x: auto;
white-space: pre-wrap;
}
.footer {
text-align: center;
color: #6b7280;
font-size: 13px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🐞 Debug Buddy</h1>
<p>Code Error Explainer for Beginners</p>
</div>
<div class="card">
<label for="language">Programming Language</label>
<select id="language">
<option value="Python">Python</option>
<option value="JavaScript">JavaScript</option>
<option value="Java">Java</option>
<option value="C">C</option>
<option value="C++">C++</option>
<option value="C#">C#</option>
<option value="HTML">HTML</option>
<option value="CSS">CSS</option>
</select>
<label for="code">Your Code</label>
<textarea
id="code"
placeholder="Paste your code here..."
></textarea>
<label for="error">Error Message</label>
<textarea
id="error"
placeholder="Paste your error message here..."
></textarea>
<button onclick="explainError()">
πŸ” Explain Error
</button>
<button class="clear-btn" onclick="clearAll()">
πŸ—‘οΈ Clear
</button>
<div class="result" id="result">
<h2>πŸ”Ž Error Explanation</h2>
<div class="result-section">
<h3>πŸ”΄ Error</h3>
<p id="errorTitle"></p>
</div>
<div class="result-section">
<h3>πŸ“Œ Why it happened</h3>
<p id="reason"></p>
</div>
<div class="result-section">
<h3>πŸ’‘ Suggested Fix</h3>
<pre id="fix"></pre>
</div>
<div class="result-section">
<h3>🧠 Tip</h3>
<p id="tip"></p>
</div>
</div>
</div>
<div class="footer">
Debug Buddy β€’ AI Code Error Explainer
</div>
</div>
<script>
function explainError() {
const language =
document.getElementById("language").value;
const code =
document.getElementById("code").value.trim();
const error =
document.getElementById("error").value.trim();
const result =
document.getElementById("result");
const errorTitle =
document.getElementById("errorTitle");
const reason =
document.getElementById("reason");
const fix =
document.getElementById("fix");
const tip =
document.getElementById("tip");
if (!code && !error) {
alert("Please enter your code or error message.");
return;
}
let title = "Unknown Error";
let explanation =
"The error could not be identified automatically.";
let suggestion =
"Check the error message and review your code.";
let advice =
"Read the error message carefully. It usually gives a clue about the problem.";
const errorText = error.toLowerCase();
if (
errorText.includes("syntaxerror") ||
errorText.includes("syntax error")
) {
title = "Syntax Error";
explanation =
"There is a problem with the structure or syntax of your code. Check brackets, quotes, commas, colons, and keywords.";
suggestion =
"Check your opening and closing brackets, quotes, commas, and the syntax required by " +
language +
".";
advice =
"Make sure every opening bracket or quote has the correct closing pair.";
}
else if (
errorText.includes("nameerror") ||
errorText.includes("not defined")
) {
title = "Name / Variable Error";
explanation =
"Your code is trying to use a variable, function, or name that has not been defined.";
suggestion =
"Check the spelling of the variable or function and make sure it is defined before you use it.";
advice =
"Variable names are often case-sensitive. Check spelling and capitalization.";
}
else if (
errorText.includes("typeerror")
) {
title = "Type Error";
explanation =
"Your code is trying to perform an operation using an incompatible data type.";
suggestion =
"Check the data types of the values involved and convert them when necessary.";
advice =
"Before performing an operation, make sure the values have compatible types.";
}
else if (
errorText.includes("indexerror") ||
errorText.includes("out of range")
) {
title = "Index Error";
explanation =
"Your code is trying to access an item at an index that does not exist.";
suggestion =
"Check the length of your list, array, or string before accessing an index.";
advice =
"Remember that many programming languages start counting indexes from 0.";
}
else if (
errorText.includes("indentationerror")
) {
title = "Indentation Error";
explanation =
"The indentation of your code is inconsistent or incorrect.";
suggestion =
"Check the spaces or tabs at the beginning of each line.";
advice =
"Use consistent indentation throughout your program.";
}
else if (
errorText.includes("referenceerror")
) {
title = "Reference Error";
explanation =
"JavaScript is trying to access a variable or object that does not exist in the current scope.";
suggestion =
"Check whether the variable is declared and whether its spelling is correct.";
advice =
"Make sure variables are declared before they are used.";
}
else if (
errorText.includes("nullpointerexception")
) {
title = "Null Pointer Exception";
explanation =
"Your program is trying to use an object that currently contains a null value.";
suggestion =
"Check whether the object is null before accessing its properties or methods.";
advice =
"Always verify that an object exists before using it.";
}
else if (
errorText.includes("modulenotfounderror") ||
errorText.includes("module not found")
) {
title = "Module Not Found";
explanation =
"The program cannot find the library or module that your code is trying to import.";
suggestion =
"Check the module name and make sure the required package is installed.";
advice =
"Verify the package name and your project's environment.";
}
result.style.display = "block";
errorTitle.textContent =
title + " (" + language + ")";
reason.textContent =
explanation;
fix.textContent =
suggestion;
tip.textContent =
advice;
}
function clearAll() {
document.getElementById("code").value = "";
document.getElementById("error").value = "";
document.getElementById("result").style.display =
"none";
}
</script>
</body>
</html>