This is a solution to the Calculator app challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Note: Delete this note and update the table of contents based on what sections you keep.
A project of a calculator web page with a beautiful design with 3 themes
Users should be able to:
- See the size of the elements adjust based on their device's screen size
- Perform mathmatical operations like addition, subtraction, multiplication, and division
- Adjust the color theme based on their preference
- Bonus: Have their initial theme preference checked using
prefers-color-scheme
and have any additional changes saved in the browser
- Solution URL: Repository
- Live Site URL: Live site
I inpruve my CSS skills and learn more about JavaScript
- Semantic HTML5 markup
- CSS custom properties
- JavaScript
I learned more about some functions of JavaScript
document.addEventListener('DOMContentLoaded', function () {
const themeOptions = document.querySelectorAll('.theme-option');
themeOptions.forEach(option => {
option.addEventListener('click', function () {
const selectedTheme = this.getAttribute('data-theme');
document.documentElement.setAttribute('data-theme', selectedTheme);
})
})
})
function appendToResult(value) {
document.getElementById('result').value += value;
}
function calculateResult() {
try {
document.getElementById('result').value = eval(document.getElementById('result').value);
} catch (error) {
document.getElementById('result').value = 'Error';
}
}
function clearResult() {
document.getElementById('result').value = '';
}
function deleteLastCharacter() {
var currentResult = document.getElementById('result').value;
document.getElementById('result').value = currentResult.slice(0, -1);
}
I want to learn more about JavaScript and what this language can do
- Website - Gabriel | Red Cat
- Frontend Mentor - Gabriel Red
- Twitter - Gabriel | Red Cat