Giter Site home page Giter Site logo

vlambo3 / calculator Goto Github PK

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

This is a simple yet functional calculator I've developed using HTML, CSS, and JavaScript. It performs basic arithmetic operations such as addition, subtraction, multiplication, and division, and allows for chaining multiple operations together. Happy calculating! 🧮

Home Page: https://calculator-blue-five.vercel.app

HTML 48.02% JavaScript 25.65% CSS 26.34%
css html javascript

calculator's Introduction

Preview

You can view the calculator in action here.

Main Functions

add(valueReceived)

This function is responsible for appending the provided value to the calculator screen. It takes a parameter valueReceived, representing the value to be appendede. It utilizes document.getElementById('screen') to retrieve the screen element by its identifier and then updates the value field by concatenating the new value.

function add(valueReceived) {
    document.getElementById('screen').value += value;
}

calculate()

The calculate() funciont is executed when the equal (=) button is pressed on the calculator. First, it retrieves the current value on the screen using document.getElementById('screen').value. Then, it utilizes the eval() function to evaluate the mathematical expression represented by the screen value. The result is stored in the result variable. Finally, the screen value is updated with the calculated result.

function calcular() {
    const screenValue = document.getElementById('screen').value;
    const result = eval(screenValue);
    document.getElementById('screen').value = result;
}

It´s important to note that the use of eval() can pose security risks if users are allowed to iput arbitrary code. In this case, we assume that the code will only be excecuted in a secure environment.

deleteScreen()

The deleteScreen() is used to erase the content of the calculator screen. It simply assigns an empty string to the value field of the screen element.

function deleteScreen() {
    document.getElementById('screen').value = '';
}

Integration with HTML and CSS

To utilize these functions, ensure you have an HTML element with the id "screen" representing the calculator display. You can find the corresponding HTML and CSS code in the files provided in the repository.

calculator's People

Contributors

vlambo3 avatar

Stargazers

philip r brenan avatar

Watchers

 avatar

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.