<title>Faluty Calculator</title>
<div id="main">
    <div id="display"><h1 id="result"></h1></div>
    <section id="key-holder">
        <button class="keys">1</button>
        <button class="keys">2</button>
        <button class="keys">3</button>
        <button class="keys">4</button>
        <button class="keys">5</button>
        <button class="keys">6</button>
        <button class="keys">7</button>
        <button class="keys">8</button>
        <button class="keys">9</button>
        <button class="keys">0</button>
        <button class="keys">.</button>
        <button class="keys" id="equals">=</button>
        <button class="keys operator">+</button>
        <button class="keys operator">/</button>
        <button class="keys operator">*</button>
        <button class="keys operator">-</button>
        <button class="keys operator" id="clear">C</button>
    </section>
</div>

</body>
<style>
#clear{margin-right: 68%;}
#display{
    display: flex;overflow:auto;
    align-items: center;
justify-content: center;font-size: 1.5;color:wheat}
h1{
    margin-bottom:0px}
*{
    font-family:'Lucida Sans'}
body{
    background:radial-gradient(black,black);
    margin:0px;padding:0pc;display: flex;flex-direction: column;align-items: center;
    height:100dvh;}
#main{
    width:30%;
    height:90%;
    margin-top:2%;
    background-image:url(GlassMorphicBackground.jpg);
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    border-radius: 20px;
    display: flex;flex-direction: column;align-items: center;}
#display{
    width:95%;
    height:25%;
    background-color: rgba(128, 128, 128, 0.4);
    margin-top:5%;
    margin-bottom:5%;}
#key-holder{
    width:95%;
    height:70%;
    display: flex;
    justify-content: center;
    gap:10px;margin-top:1%;margin-bottom:1%;
    flex-wrap: wrap;}
.keys{
    width:20%;
    background-color: rgba(255,255,255,0.2);
    color:white;font-size: 2em;
    display: flex;
    align-items: center;
    justify-content: center;border:none;
transform: all 0.2s ease;}
.operator{
    background:rgba(248, 121, 1, 0.7    )}
.keys:hover{
    scale: 1.1;
    border-radius: 10px;
    background-color: rgba(255,255,255,0.5);
    color:black;font-weight: bold;
}.operator:hover{
    background:orange}

</style>
<script>
let buttons = document.querySelectorAll('button')  
let display = document.getElementById('result')
let equal = document.getElementById('equals')
let randomNum;
console.log(buttons);
   
buttons.forEach(element => {
    if(element.innerHTML == '='){console.log('ijikul');}
    else if(element.innerHTML == 'C'){element.addEventListener('click',()=>{result.innerHTML = ''});}
    else{
    element.addEventListener('click',()=>{result.innerText+=element.innerHTML;})}
});

equal.addEventListener('click',()=>{
    randomNum = Math.round(Math.random()*10)
    console.log(randomNum);

    
    try{
        final = eval(display.innerHTML);
        display.innerHTML = final
    }
    
    catch(error){
        display.innerText = ''
    } 
if(final=='Infinity'){display.innerText = 'Not defined'}
    if(randomNum==5 || randomNum==4){
        display.innerText = Math.round(Math.random()*final)
    }
})
</script>
</html>function calculate(number1,number2,operator){
if (!number1 || !number2){
    return "Invalid number"
}
if (!['*','-','/','+'].includes(operator)){
    return "Invalid operator"
}
switch(operator){
  case "+":
    return number1 + number2;
  case "/":
    return number1 * number2;
  case "*":
    return number1 * number2;
  case "-":
    return number1 - number2;
 }
}
console.log(calculate(5,6,"+"))<!-- Create a simple Program to build the Calculator in JavaScript using with HTML and CSS web languages. -->  
<!DOCTYPE html>  
<html lang = "en">  
<head>  
<title> JavaScript Calculator </title>  
  
<style>  
h1 {  
    text-align: center;  
    padding: 23px;  
    background-color: skyblue;  
    color: white;  
    }  
  
#clear{  
width: 270px;  
border: 3px solid gray;  
    border-radius: 3px;  
    padding: 20px;  
    background-color: red;  
}  
  
.formstyle  
{  
width: 300px;  
height: 530px;  
margin: auto;  
border: 3px solid skyblue;  
border-radius: 5px;  
padding: 20px;  
}  
  
  
  
input  
{  
width: 20px;  
background-color: green;  
color: white;  
border: 3px solid gray;  
    border-radius: 5px;  
    padding: 26px;  
    margin: 5px;  
    font-size: 15px;  
}  
  
  
#calc{  
width: 250px;  
border: 5px solid black;  
    border-radius: 3px;  
    padding: 20px;  
    margin: auto;  
}  
  
</style>  
  
</head>  
<body>  
<h1> Calculator Program in JavaScript </h1>  
<div class= "formstyle">  
<form name = "form1">  
      
    <!-- This input box shows the button pressed by the user in calculator. -->  
  <input id = "calc" type ="text" name = "answer"> <br> <br>  
  <!-- Display the calculator button on the screen. -->  
  <!-- onclick() function display the number prsses by the user. -->  
  <input type = "button" value = "1" onclick = "form1.answer.value += '1' ">  
  <input type = "button" value = "2" onclick = "form1.answer.value += '2' ">  
  <input type = "button" value = "3" onclick = "form1.answer.value += '3' ">  
   <input type = "button" value = "+" onclick = "form1.answer.value += '+' ">  
  <br> <br>  
    
  <input type = "button" value = "4" onclick = "form1.answer.value += '4' ">  
  <input type = "button" value = "5" onclick = "form1.answer.value += '5' ">  
  <input type = "button" value = "6" onclick = "form1.answer.value += '6' ">  
  <input type = "button" value = "-" onclick = "form1.answer.value += '-' ">  
  <br> <br>  
    
  <input type = "button" value = "7" onclick = "form1.answer.value += '7' ">  
  <input type = "button" value = "8" onclick = "form1.answer.value += '8' ">  
  <input type = "button" value = "9" onclick = "form1.answer.value += '9' ">  
  <input type = "button" value = "*" onclick = "form1.answer.value += '*' ">  
  <br> <br>  
    
    
  <input type = "button" value = "/" onclick = "form1.answer.value += '/' ">  
  <input type = "button" value = "0" onclick = "form1.answer.value += '0' ">  
    <input type = "button" value = "." onclick = "form1.answer.value += '.' ">  
    <!-- When we click on the '=' button, the onclick() shows the sum results on the calculator screen. -->  
  <input type = "button" value = "=" onclick = "form1.answer.value = eval(form1.answer.value) ">  
  <br>   
  <!-- Display the Cancel button and erase all data entered by the user. -->  
  <input type = "button" value = "Clear All" onclick = "form1.answer.value = ' ' " id= "clear" >  
  <br>   
    
</form>  
</div>  
</body>  
</html>  <!-- Create a simple Program to build the Calculator in JavaScript using with HTML and CSS web languages. -->  
<!DOCTYPE html>  
<html lang = "en">  
<head>  
<title> JavaScript Calculator </title>  
  
<style>  
h1 {  
    text-align: center;  
    padding: 23px;  
    background-color: skyblue;  
    color: white;  
    }  
  
#clear{  
width: 270px;  
border: 3px solid gray;  
    border-radius: 3px;  
    padding: 20px;  
    background-color: red;  
}  
  
.formstyle  
{  
width: 300px;  
height: 530px;  
margin: auto;  
border: 3px solid skyblue;  
border-radius: 5px;  
padding: 20px;  
}  
  
  
  
input  
{  
width: 20px;  
background-color: green;  
color: white;  
border: 3px solid gray;  
    border-radius: 5px;  
    padding: 26px;  
    margin: 5px;  
    font-size: 15px;  
}  
  
  
#calc{  
width: 250px;  
border: 5px solid black;  
    border-radius: 3px;  
    padding: 20px;  
    margin: auto;  
}  
  
</style>  
  
</head>  
<body>  
<h1> Calculator Program in JavaScript </h1>  
<div class= "formstyle">  
<form name = "form1">  
      
    <!-- This input box shows the button pressed by the user in calculator. -->  
  <input id = "calc" type ="text" name = "answer"> <br> <br>  
  <!-- Display the calculator button on the screen. -->  
  <!-- onclick() function display the number prsses by the user. -->  
  <input type = "button" value = "1" onclick = "form1.answer.value += '1' ">  
  <input type = "button" value = "2" onclick = "form1.answer.value += '2' ">  
  <input type = "button" value = "3" onclick = "form1.answer.value += '3' ">  
   <input type = "button" value = "+" onclick = "form1.answer.value += '+' ">  
  <br> <br>  
    
  <input type = "button" value = "4" onclick = "form1.answer.value += '4' ">  
  <input type = "button" value = "5" onclick = "form1.answer.value += '5' ">  
  <input type = "button" value = "6" onclick = "form1.answer.value += '6' ">  
  <input type = "button" value = "-" onclick = "form1.answer.value += '-' ">  
  <br> <br>  
    
  <input type = "button" value = "7" onclick = "form1.answer.value += '7' ">  
  <input type = "button" value = "8" onclick = "form1.answer.value += '8' ">  
  <input type = "button" value = "9" onclick = "form1.answer.value += '9' ">  
  <input type = "button" value = "*" onclick = "form1.answer.value += '*' ">  
  <br> <br>  
    
    
  <input type = "button" value = "/" onclick = "form1.answer.value += '/' ">  
  <input type = "button" value = "0" onclick = "form1.answer.value += '0' ">  
    <input type = "button" value = "." onclick = "form1.answer.value += '.' ">  
    <!-- When we click on the '=' button, the onclick() shows the sum results on the calculator screen. -->  
  <input type = "button" value = "=" onclick = "form1.answer.value = eval(form1.answer.value) ">  
  <br>   
  <!-- Display the Cancel button and erase all data entered by the user. -->  
  <input type = "button" value = "Clear All" onclick = "form1.answer.value = ' ' " id= "clear" >  
  <br>   
    
</form>  
</div>  
</body>  
</html>  5-6=
  java script calculatorconst keys = document.querySelector('.calculator-keys');
keys.addEventListener('click', (event) => {
  // Access the clicked element
  const { target } = event;

  // Check if the clicked element is a button.
  // If not, exit from the function
  if (!target.matches('button')) {
    return;
  }

  if (target.classList.contains('operator')) {
    console.log('operator', target.value);
    return;
  }

  if (target.classList.contains('decimal')) {
    console.log('decimal', target.value);
    return;
  }

  if (target.classList.contains('all-clear')) {
    console.log('clear', target.value);
    return;
  }

  console.log('digit', target.value);
});// Function to ask for the operation

function getOperation() {

  const operation = prompt("Choose an operation: +, -, *, /");

  return operation;

}

// Function to ask for numbers

function getNumbers() {

  const num1 = parseFloat(prompt("Enter first number:"));

  const num2 = parseFloat(prompt("Enter second number:"));

  return { num1, num2 };

}

// Perform the calculation based on the operation

function calculate(operation, num1, num2) {

  switch (operation) {

    case '+':

      return num1 + num2;

    case '-':

      return num1 - num2;

    case '*':

      return num1 * num2;

    case '/':

      // Check for division by zero

      if (num2 === 0) {

        return "Cannot divide by zero";

      }

      return num1 / num2;

    default:

      return "Invalid operation";

  }

}

// Main function to run the calculator

function runCalculator() {

  const operation = getOperation();

  const { num1, num2 } = getNumbers();

  const result = calculate(operation, num1, num2);

  alert(`Result: ${result}`);

}

// Run the calculator

runCalculator();

Javascript相关代码片段

react get blue outline on routing Links

get rid of blue button effect on react links

nextjs remote url image

react router v6 basic code

lua table to json online

download video from url javascript

jquery set max length input

JS not selecting the element

react native clock

shadcn toast not showing

express folder structure

audio element

javascript set display of elem to block

react phone number input

tailwind intellisense not working with react

cannot find name 'cy'

submit form react

footer react bootstrap

angular interview questions and answers

trigger alert if button is clicked

change query params

verify control code iban javascript

react-spring

Next JS solve the Hydration error

how can i set a new expo project

generate aes key

storage capacity on browser

nix flake Javascript projects

reset udemy course progress

zod Input file schema with shadcn

wordpress rest api print json pretty

extract string csv js

remove extra space string javascript

count letters in string javascript

exract string js

lazygit nvim

ex:javascript loop

js slice last element

Multiply a number with .17 and round up to .25

sweetalert 2

booking calendar js

process.env is kept

AnimationEvent has no function name specified!

jquery date picker wordpress enque

js check in view

settimeout event in input in javascript in react

node option size

docker react app

React Modal using Dialog

how to create dynamic object in javascript

how to create global variable in postman

javascript interview questions tricky

how to create workflow request in postman

mysql json_extract array

parse response body in postman

query param generator js

jest function async API

React portal

i18next suppoeort react

puppeteer page evaluate

react router dom use navigate

react create array from another array

how to delete global variable in scripts postman

Where does closure variables stored in javascript

Where does local variables stored in javascript

nodejs là gì

addEventListener for multiple selector

js calculate opacity

nodejs create stripe payment from server easy

get child form value in parent viewchild

javascript capitalize every word in a sentence

how to use jquery in moodle

how to handle no internet error in react query

window in not defined in nextjs

cypress find element inside element

app tracking transparency react native permissions

C# Blazor list to json

puppeteer .cache folder not found

css in js

bootstrap next js