Dictionary Calculator
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
display: flex;
justify-content: space-around;
width: 80%;
max-width: 1200px;
}
.calc-container, .dict-container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 45%;
}
h1 {
color: #333;
text-align: center;
margin-bottom: 20px;
}
.calc-input, .word-input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
font-size: 16px;
border: 2px solid #ccc;
border-radius: 5px;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#calc-result, #word-definition {
color: #333;
font-size: 18px;
font-weight: bold;
text-align: center;
margin-top: 15px;
}
#word-definition {
font-weight: normal;
font-size: 16px;
}
// Function to calculate mathematical expressions
function calculate() {
const input = document.getElementById('calc-input').value;
try {
const result = eval(input); // Using eval to evaluate the mathematical expression
document.getElementById('calc-result').textContent = `Result: ${result}`;
} catch (e) {
document.getElementById('calc-result').textContent = "Invalid expression!";
}
}
// Function to get the definition of a word using an API
function getDefinition() {
const word = document.getElementById('word-input').value;
const apiKey = 'your_api_key_here'; // Replace with your API key
const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;
fetch(url)
.then(response => response.json())
.then(data => {
if (data.title === "No Definitions Found") {
document.getElementById('word-definition').textContent = "Word not found!";
} else {
const definition = data[0].meanings[0].definitions[0].definition;
document.getElementById('word-definition').textContent = `Definition: ${definition}`;
}
})
.catch(err => {
document.getElementById('word-definition').textContent = "Error fetching definition!";
});
}