Certainly! Below is a simplified version of an illness diagnosis website using HTML, CSS, and JavaScript. This example will guide users through a series of symptom-based questionnaires and provide a suggested treatment at the end.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Illness Diagnosis</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Illness Diagnosis</h1>
<div id="questionnaire">
<div class="question" id="question1">
<p>Do you have a fever?</p>
<button onclick="nextQuestion(true)">Yes</button>
<button onclick="nextQuestion(false)">No</button>
</div>
<div class="question" id="question2" style="display:none;">
<p>Do you have a cough?</p>
<button onclick="nextQuestion(true)">Yes</button>
<button onclick="nextQuestion(false)">No</button>
</div>
<div class="question" id="question3" style="display:none;">
<p>Do you have difficulty breathing?</p>
<button onclick="nextQuestion(true)">Yes</button>
<button onclick="nextQuestion(false)">No</button>
</div>
<div class="result" id="result" style="display:none;">
<h2>Suggested Treatment</h2>
<p id="treatment"></p>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS (styles.css)
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
.question, .result {
margin: 20px 0;
}
button {
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
background-color: #007BFF;
color: white;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
JavaScript (script.js)
let symptoms = [];
function nextQuestion(answer) {
const currentQuestion = document.querySelector('.question:not([style*="display: none"])');
const nextQuestion = currentQuestion.nextElementSibling;
if (nextQuestion && nextQuestion.classList.contains('question')) {
currentQuestion.style.display = 'none';
nextQuestion.style.display = 'block';
symptoms.push(answer);
} else {
currentQuestion.style.display = 'none';
document.getElementById('result').style.display = 'block';
suggestTreatment();
}
}
function suggestTreatment() {
const treatmentElement = document.getElementById('treatment');
if (symptoms.includes(true)) {
if (symptoms[2]) {
treatmentElement.textContent = "Seek immediate medical attention.";
} else if (symptoms[1]) {
treatmentElement.textContent = "Consider over-the-counter medications and rest.";
} else {
treatmentElement.textContent = "Monitor symptoms and rest.";
}
} else {
treatmentElement.textContent = "You may not need treatment. Monitor symptoms.";
}
}
Explanation
-
HTML:
- The structure includes a container with a series of questions and a result section.
- Each question is a
div with a unique ID.
- The result section is initially hidden and displays the suggested treatment.
-
CSS:
- Basic styling for the container, questions, and buttons.
- Hidden questions are managed using inline styles.
-
JavaScript:
- The
nextQuestion function handles the flow between questions.
- The
suggestTreatment function evaluates the symptoms and suggests a treatment based on the answers.
This is a basic implementation. You can expand it by adding more questions, refining the treatment suggestions, and improving the user interface.