GithubHelp home page GithubHelp logo

witchdevelops / calculator-js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 57 KB

Home Page: https://witchdevelops.github.io/Calculator-JS/

License: Mozilla Public License 2.0

HTML 17.65% CSS 35.56% SCSS 19.15% JavaScript 27.65%

calculator-js's Introduction

Frontend Mentor - Calculator app solution

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.

Table of contents

Overview

The challenge

Users should be able to:

  • See the size of the elements adjust based on their device's screen size
  • Perform mathematical operations like addition, subtraction, multiplication, and division
  • Also on decimal numbers
  • Use either screen or keyboard
  • Adjust the color theme based on their preference
  • Have their initial theme preference checked using prefers-color-scheme and have any additional changes saved in the browser

Screenshot

image image image

Links

My process

I consult MDN docs and W3Schools docs a lot and I also use chatGPT to help with debugging. It's really good at detecting typos and double checking variable and function names.

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • vanilla JavaScript
  • Flexbox
  • CSS Grid
  • Mobile-first workflow
  • :has() and radio input for theme switcher

What I learned

I learned how to implement a theme switcher. It is surprisingly easy! All you need to do is have all your colours defined as variables, then by the power of :has() combined with radio buttons you can easily toggle between various colour presents. For example:

:root:has(#theme2:checked) {
  --variable_name: #color;
}

As :has() isn't currently supported in Mozilla Firefox, I added a fallback with a class assigned with JavaScript.

Continued development

One drawback of implementing a theme switcher combined with a radio input is that I couldn't make it work using SASS. This is probably because SASS declares variables without using the :root selector. Using @at-root didn't compile. I have yet to figure out a solution to implementing a theme switcher while having styles written in SASS. Similarly, detecting user preference regarding color scheme and assigning a class with JavaScript for the theme switcher clashes, so in Mozilla the switcher doesn't work with manual input. I have yet to figure it out.

Useful resources

  • CSS theme switcher using :has - This video was super helpful to understand both how :has selector works and how to use it to change the variables declared on the :root element to create a theme switcher with CSS.
  • Frontend Masters project by Brian Holt - This is a great course overall, so highly recommend, and this lesson in particular was very helpful to consult with whenever I felt stuck with JS logic.
  • Animated switch for radio buttons - This codepen shows how to achieve smooth animation for theme toggler.
  • Take input from keyboard - This codepen helped me to implement keyboard input functionality.
  • Regex 101 - This resource is very handy when working with regexes. It allows test a string against regex and debug it. It also comes with an inbuild quick reference for a refresher.

Author

calculator-js's People

Contributors

witchdevelops avatar

Watchers

 avatar

calculator-js's Issues

refactor the code

  • change divs to buttons for accessibility
  • refactor functions to be arrow functions
  • add "prefers color scheme" light, dark, high contrast (CSS?)
  • add JS fallback for theme switcher for browsers that don't support :has()

bug! no max-width

calculator gets stretched out infinitely when the display shows a long number, longer than display's width. Fix this!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.