0% found this document useful (0 votes)
9 views6 pages

Script

The document contains JavaScript code for a calculator application that handles basic arithmetic operations and user interactions. It includes event listeners for number and operation buttons, as well as functions for handling calculations, clearing inputs, and displaying results. Additionally, there are features for visual effects and audio cues during user interactions.

Uploaded by

menaboc850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Script

The document contains JavaScript code for a calculator application that handles basic arithmetic operations and user interactions. It includes event listeners for number and operation buttons, as well as functions for handling calculations, clearing inputs, and displaying results. Additionally, there are features for visual effects and audio cues during user interactions.

Uploaded by

menaboc850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

document.

addEventListener('DOMContentLoaded',function(){ //Wait for the while DOM


tree to load or Ů
let firstnumber1 = null; //if the number is null that means the user did no
number imputs in the current opperation
let firstnumber2 = null; //null = "." was not pressed; 0 = the user clicked
"."
let operationkeypressed = false; // false = operation key was not pressed
let secondnumber1 = null; //null = no 2nd number
let secondnumber2 = null; //null = "." was not pressed regarding the 2nd
number; 0 = the user clicked "."
let operation = null;
let final = null;

let maxnumberlenght = 10;

function clear(){
firstnumber1 = null;
firstnumber2 = null;
operationkeypressed = false;
secondnumber1 = null;
secondnumber2 = null;
operation = null;
document.querySelector("output p:first-child").innerText = "";
document.querySelector("output").style.color = "rgba(66, 66, 66, 0.616)";
if ((Math.floor(Math.random() * (100-1 + 1))+1) == 1){
document.querySelector("output p:last-child").innerText =
"ILoveIsabelle";//veryneeded
}else{
document.querySelector("output p:last-child").innerText =
"0000000000000";
}

}
//REMEMBER: to.Exponentiol();

//TODO: add some funny LUA reference

//events and event loopers


for (i=1; i < 11; i++) {
document.querySelector(`#numbers > div:nth-child($
{i})`).addEventListener('click',function(event){
numberclick(event)
})
}
for (i=1; i < 7; i++) {
document.querySelector(`#operations > div:nth-child($
{i})`).addEventListener('click',function(event){
operationclick(event)
})
}

document.querySelector(`#numbers > div:nth-


child(11)`).addEventListener('click',function(event){
dotclick()
})
document.querySelector(`#numbers > div:last-
child`).addEventListener('click',function(event){
clear()
})
document.querySelector(`#operations > div:last-
child`).addEventListener('click',function(event){
finish()
})

document.querySelector(`.ooo > img:first-


child`).addEventListener('click',function(event){
drill(1)
})
document.querySelector(`.ooo > img:last-
child`).addEventListener('click',function(event){
drill(2)
})

//functions
function numberclick(event){
document.querySelector("output").style.color = "white";
if (firstnumber1 === null && String(firstnumber1).length <=
maxnumberlenght && firstnumber2 === null) {
firstnumber1 = event.target.innerText;
document.querySelector("output p:last-child").innerText =
firstnumber1;
}else if(operationkeypressed === false &&
String(firstnumber1).length <= maxnumberlenght){
if (firstnumber1 == 0 && firstnumber2 === null){
firstnumber1 = event.target.innerText;
}else{
firstnumber1 += event.target.innerText;
}
document.querySelector("output p:last-child").innerText =
firstnumber1;
}else if(operationkeypressed === true && secondnumber1 == null &&
String(secondnumber1).length <= maxnumberlenght && secondnumber2 === null){
secondnumber1 = event.target.innerText;
document.querySelector("output p:last-child").innerText =
secondnumber1;
}else if(operationkeypressed === true && secondnumber1 !== null &&
String(secondnumber1).length <= maxnumberlenght){
if (secondnumber1 == 0 && secondnumber2 === null){
secondnumber1 = event.target.innerText;
}else{
secondnumber1 += event.target.innerText;
}
document.querySelector("output p:last-child").innerText =
secondnumber1;
}
x = firstnumber1+" "+operation+" "+secondnumber1
document.querySelector("output p:first-child").innerText =
x.toString().replace('null',"").replace('null',"");
console.log(firstnumber1,operation,secondnumber1)
}

function operationclick(event){

if (firstnumber1 !== null && secondnumber1 === null &&


event.target.innerText != "%" && event.target.innerText != "√"){
operation = event.target.innerText;
operationkeypressed = true;
document.querySelector("output p:last-child").innerText =
event.target.innerText;

}else{
if (event.target.innerText == "%" && secondnumber1 !== null){
secondnumber1 = (secondnumber1 / 100) * firstnumber1;
x = firstnumber1+" "+operation+" "+secondnumber1
document.querySelector("output p:first-child").innerText =
x.toString().replace('null',"").replace('null',"");
document.querySelector("output p:last-child").innerText =
secondnumber1;
}else if (event.target.innerText == "%" && operation === null){
firstnumber1 = 0;
document.querySelector("output p:first-child").innerText = 0;
document.querySelector("output p:last-child").innerText = 0;
}else if (event.target.innerText == "√" && operation === null){
firstnumber1 =
Math.sqrt(Number(firstnumber1)).toString().substring(0,6)
document.querySelector("output p:first-child").innerText =
firstnumber1;
document.querySelector("output p:last-child").innerText =
firstnumber1;
}else if (event.target.innerText == "√" && secondnumber1 !== null){
secondnumber1 =
Math.sqrt(Number(secondnumber1)).toString().substring(0,6)
x = firstnumber1+" "+operation+" "+secondnumber1
document.querySelector("output p:first-child").innerText =
x.toString().replace('null',"").replace('null',"");
document.querySelector("output p:last-child").innerText =
secondnumber1;
}
}
}

function dotclick(){
if (operationkeypressed === false){
if (firstnumber2 === null ){
if (firstnumber1 === null) {
firstnumber1 = "0";
}
firstnumber2 = 0;
firstnumber1 += ".";
console.log(firstnumber1)
}

}else{
if (secondnumber2 === null){
if (secondnumber1 === null) {
//
require("Virus") <-- real(fake[plz do not ban{plz}])
secondnumber1 = 0;
}
secondnumber2 = 0;
secondnumber1 += ".";
}
}
}
function finish(){
//TODO: the thing
if (firstnumber1 !== null && operation !== null && secondnumber1 !== null){
if (operation == "+"){
final = Number(firstnumber1)+Number(secondnumber1);
}else if (operation == "-"){
final = Number(firstnumber1)-Number(secondnumber1);
}else if (operation == "x"){
final = Number(firstnumber1)*Number(secondnumber1);
}else if (operation == "÷"){
if (secondnumber1 == 0){
final = "Bro don't";
}else{
final = Number(firstnumber1)/Number(secondnumber1);
}

}
clear();
document.querySelector("output").style.color = "white";

if (final.toString().length <= maxnumberlenght){


firstnumber1 = final;
x = final
document.querySelector("output p:first-child").innerText =
x.toString();
document.querySelector("output p:last-child").innerText = final;
}else{
document.querySelector("output p:last-child").innerText =
Number(final.toString().substring(0,10)).toExponential();
}
final = null;
}

let drilled1 = false;


let drilled2 = false;
let degrees = 0;
let runner;
let drilling = false;
function drill(bro){

if ((drilled1 === false || drilled2 === false) && ((bro === 1 && drilled1
=== false && drilling === false) || (bro === 2 && drilled2 === false && drilling
=== false))){

if (bro === 1 && drilled1 === false && drilling === false){
drilling = true;
new Audio("unscrew.m4a").play();
runner = setInterval(function(){
degrees+=4;
document.querySelector(`.ooo > img:first-
child`).style.webkitTransform = 'rotate(' + degrees + 'deg)';
},1)
}else if (bro === 2 && drilled2 === false && drilling === false){
drilling = true;
new Audio("unscrew.m4a").play();
runner = setInterval(function(){
degrees+=4;
document.querySelector(`.ooo > img:last-
child`).style.webkitTransform = 'rotate(' + degrees + 'deg)';
},1)
}

setTimeout(function() {
clearInterval(runner);
if (bro === 1){
if (drilled2 === false){
drilled1 = true
document.querySelector(`.ooo > img:first-child`).src =
"screw-head-2none.png";
let rotater;
degrees = 0;
let br = document.querySelector(`main > div:first-child`);
let xa = 0;
let ya = 0;
rotater = setInterval(function(){

if (degrees <= 45){


xa+=3.4;
ya+=6.1;

degrees-=1;

br.style.webkitTransform = `rotate(` + degrees +


`deg) translate(${xa}px,${ya}px)`;
}

},8)
setTimeout(function() {
clearInterval(rotater);
drilling = false;
},400)
}else{
finaldrill(-45)
}

}else if (bro === 2 ){


if (drilled1 === false){
drilled2 = true
document.querySelector(`.ooo > img:last-child`).src =
"screw-head-2none.png";
let rotater;
degrees = 0;
let br = document.querySelector(`main > div:first-child`);
let xa = 0;
let ya = 0;
rotater = setInterval(function(){

if (degrees <= 45){


xa-=3.4;
ya+=6.1;

degrees+=1;

br.style.webkitTransform = `rotate(` + degrees +


`deg) translate(${xa}px,${ya}px)`;
}

},8)
setTimeout(function() {
clearInterval(rotater);
drilling = false;
},400)
}else{
finaldrill(45)
}

}
}, 2000);
}
}
function finaldrill(deg){
document.querySelector(`.ooo > img:first-child`).src = "screw-head-
2none.png";
document.querySelector(`.ooo > img:last-child`).src = "screw-head-
2none.png";
drilling = true;
let rotater;
let rotater2;
degrees = 0;
let br = document.querySelector(`main > div:first-child`);
let br2 = document.querySelector(`h1`);
let xa = 0;
let ya = 15;
rotater = setInterval(function(){
ya+=3;

br.style.top = `${ya}%`;
},5)
setTimeout(function() {
clearInterval(rotater);
new Audio("LODd) (1).mp3").play();
document.body.style.backgroundImage = "url('arch.jpg')";
document.querySelector(`#credits > div:last-child`).style.display =
'block';
br2.style.position = "absolute";
ya=0;
rotater2 = setInterval(function(){
ya+=3;

br2.style.top = `${ya}%`;
},5)
setTimeout(function() {
clearInterval(rotater2);
},7000)
},70)
}
})

//TODO: more TODO's and more funny stuff

You might also like