Coder Social home page Coder Social logo

vishwas567917 / faulty-calculator Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 3 KB

Faulty Calculator is a web-based calculator built with HTML and JavaScript, designed to intentionally produce incorrect results. Ideal for demonstrating error handling, testing robustness, and exploring the impact of deliberate bugs in a fun way.

HTML 31.67% JavaScript 68.33%
random-calculator random-number-generator script-generates

faulty-calculator's Introduction

Random Calculator with Incorrect Results

This repository contains a simple JavaScript application that simulates a calculator with a twist. The calculator randomly decides whether to perform the correct operation or an incorrect one, creating a fun and unexpected experience for users.

Code Structure

The application is structured as follows:

  • HTML: Sets up a basic HTML page with a script tag for the JavaScript code.
  • JavaScript: Contains the logic for performing calculations and randomly deciding whether to perform the correct or incorrect operation.

How It Works

  1. The script generates a random number to determine if it should perform the correct or incorrect operation.
  2. It prompts the user for two numbers and an operation to perform.
  3. If the random number is greater than 0.1, the correct operation is performed, and the result is displayed.
  4. If the random number is less than or equal to 0.1, the operation is changed to a different (incorrect) one using a predefined object, and an incorrect result is displayed.

Example

let random = Math.random();
let a = prompt("Enter first number");
let c = prompt("Enter operation");
let b = prompt("Enter second number");

let obj = {
    "+": "-",
    "*": "+",
    "-": "/",
    "/": "**",
};

if (random > 0.1) {
    console.log(`The correct result for ${a} ${c} ${b} is ${eval(`${a} ${c} ${b}`)}`);
} else {
    c = obj[c];
    console.log(`The incorrect result for ${a} ${c} ${b} is ${eval(`${a} ${c} ${b}`)}`);
}


This README outlines the purpose and functionality of the JavaScript code, provides an example, and includes a section for contributions and a disclaimer for potential inaccuracies due to the randomization. You can copy and paste this markdown into your README.md file on GitHub and adjust it as needed.

faulty-calculator's People

Contributors

vishwas567917 avatar

Stargazers

Sudhanshu Ambastha avatar  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.