Create an application using javascript for clean and green environment
- User
Create an application using javascript for clean and green environment
- Assistant
Create an application using javascript for clean and green environment
Creating an application that promotes a clean and green environment is a commendable initiative. Below is a basic outline and code for a web-based application using HTML, CSS, and JavaScript. This application will educate users about eco-friendly practices, provide tips, and encourage community engagement. The application incorporates interactive elements like quizzes and community pledges.
clean-green-app/
│
├── index.html
├── styles.css
└── app.js
index.html)<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clean & Green Environment</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Clean and Green Environment Initiative</h1>
<nav>
<ul>
<li><a href="#tips">Eco Tips</a></li>
<li><a href="#quiz">Eco Quiz</a></li>
<li><a href="#pledge">Community Pledge</a></li>
</ul>
</nav>
</header>
<section id="tips">
<h2>Eco-Friendly Tips</h2>
<ul>
<li>Reduce, Reuse, Recycle.</li>
<li>Conserve Water and Electricity.</li>
<li>Use Public Transportation or Carpool.</li>
<li>Plant a Tree.</li>
</ul>
</section>
<section id="quiz">
<h2>Eco Quiz</h2>
<p>Test your knowledge about the environment!</p>
<button id="startQuizBtn">Start Quiz</button>
<div id="quizContainer" class="hidden">
<p id="question"></p>
<button class="answerBtn" data-answer="true">True</button>
<button class="answerBtn" data-answer="false">False</button>
</div>
<p id="quizResult" class="hidden"></p>
</section>
<section id="pledge">
<h2>Community Pledge</h2>
<p>Join us in our endeavor to make the planet cleaner and greener.</p>
<button id="pledgeBtn">Take the Pledge</button>
<p id="pledgeMessage" class="hidden">Thank you for your commitment to a greener planet!</p>
</section>
<script src="app.js"></script>
</body>
</html>
styles.css)body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}
header {
background: #4caf50;
color: #fff;
padding: 20px;
text-align: center;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
display: inline;
margin: 0 15px;
}
section {
margin: 20px;
padding: 20px;
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.hidden {
display: none;
}
button {
background-color: #4caf50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
app.js)document.addEventListener('DOMContentLoaded', () => {
const startQuizBtn = document.getElementById('startQuizBtn');
const quizContainer = document.getElementById('quizContainer');
const questionElement = document.getElementById('question');
const answerBtns = document.querySelectorAll('.answerBtn');
const quizResult = document.getElementById('quizResult');
const pledgeBtn = document.getElementById('pledgeBtn');
const pledgeMessage = document.getElementById('pledgeMessage');
// Define a simple quiz
const quiz = [
{
question: "The Amazon Rainforest produces 20% of the world's oxygen.",
answer: "true"
}
];
let currentQuestion = 0;
startQuizBtn.addEventListener('click', () => {
quizContainer.classList.remove('hidden');
displayQuestion();
});
answerBtns.forEach(button => {
button.addEventListener('click', () => {
checkAnswer(button.dataset.answer);
});
});
function displayQuestion() {
const question = quiz[currentQuestion];
questionElement.textContent = question.question;
}
function checkAnswer(answer) {
if (answer === quiz[currentQuestion].answer) {
quizResult.textContent = "Correct! The Amazon Rainforest is vital for global oxygen supply.";
} else {
quizResult.textContent = "Incorrect. Remember, every part of nature is crucial!";
}
quizResult.classList.remove('hidden');
}
pledgeBtn.addEventListener('click', () => {
pledgeMessage.classList.remove('hidden');
});
});
This application is a simple, educational tool to engage users and spread awareness about adopting a more environmentally friendly lifestyle. You can further enhance the app by adding more topics, interactive content, or even integrating location-based features to let users join local cleanup events.
Not yet included in a published release.