Giter Club home page Giter Club logo

pengumpulan-react-i-ukm-programming's Introduction

Yo.


I likes pixel art, RPGs, and the trinity that is the Isekai-System-Wuxia genre
My site

I've used, Python, Flutter-Dart, React-JS, Godot, Octave-MatLab, Java, Bash, Pascal, C++.

Stats

Profile pic by Johnny Goodwill (@sunlighttofastora)

pengumpulan-react-i-ukm-programming's People

Contributors

roberika avatar

Watchers

 avatar

pengumpulan-react-i-ukm-programming's Issues

fixing problem

ini versi yg kubuat, cubo kau cek problemnyo dimano untuk kodingan kau samo kodingan ini
kalo ado yg nak di tanyoke bole bahas di grup / chat aku pribadi

const [input, setInput] = useState({ numA: 0, numB: 0, operator: '+' })
const operators = ['+', '-', '*', '/', '^', '%'];

const calculate = () => {
  const numA = parseFloat(input.numA);
  const numB = parseFloat(input.numB);
  return input.operator === '+' ? numA + numB :
    input.operator === '-' ? numA - numB :
      input.operator === '*' ? numA * numB :
        input.operator === '/' ? numA / numB :
          input.operator === '^' ? numA ^ numB :
            input.operator === '%' ? numA % numB : 0
}

const handleSetInput = (num, e) => {
  const userInput = e.target.value;
  if (num === 'operator' && operators.indexOf(userInput.slice(-1)) !== -1) {
    setInput((prev) => ({
      ...prev,
      [num]: prev.operator.length !== 0 ? userInput.slice(1) : userInput
    }))
  } else if (num !== 'operator') {
    setInput((prev) => ({
      ...prev, [num]: prev[num] === 0 ? userInput.slice(1) : userInput
    }))
  }
  calculate();
}

return (
  <form className="card">

    <input type="number" value={input.numA}
      onChange={(e) => handleSetInput('numA', e)} />
    <br />

    <input type="text" value={input.operator}
      onChange={(e) => handleSetInput('operator', e)} />
    <br />

    <input type="number" value={input.numB}
      onChange={(e) => handleSetInput('numB', e)} />
    <br />

    Result = {calculate()}

  </form>
)

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.