Skip to content

Commit

Permalink
audio updated
Browse files Browse the repository at this point in the history
  • Loading branch information
amanbind898 committed Sep 12, 2023
1 parent 440eb60 commit cb75c3b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Binary file added click-21156.mp3
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</div>

<audio id="keypressSound">
<source src="office-calculator-single-button-press.mp3" type="audio/mpeg">
<source src="click-21156.mp3" type="audio/mpeg">
</audio>

</body>
Expand Down
32 changes: 18 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,43 @@ document.addEventListener('DOMContentLoaded', function () {
let buttons = document.querySelectorAll('.button');
let inputField = document.querySelector('.input');
let keypressSound = document.getElementById('keypressSound');

// Preload the audio file
keypressSound.preload = 'auto';

buttons.forEach((button) => {
button.addEventListener('click', (e) => {
let buttonText = e.target.innerHTML;
if(buttonText==='X')
buttonText='*'

// Play the keypress sound immediately
keypressSound.currentTime = 0;
keypressSound.play();

if (buttonText === 'X') {
buttonText = '*';
}

if (buttonText === '=') {
try {
string = eval(string);
inputField.value = string;
} catch (error) {
inputField.value = 'Error';
}
}
else if(buttonText === 'DEL')
{
string=string.substring(0,string.length-1);
inputField.value=string;
}
else if (buttonText === 'AC') {
} else if (buttonText === 'DEL') {
string = string.substring(0, string.length - 1);
inputField.value = string;
} else if (buttonText === 'AC') {
string = '0'; // Set the input to '0' on All Clear
inputField.value = string;
} else {
if (string === '0') {
string = buttonText; // Replace '0' with the new button value
}

else {
} else {
string = string + buttonText;
}
inputField.value = string;
}
// Play the keypress sound
keypressSound.play();
});
});
});
Binary file removed office-calculator-single-button-press.mp3
Binary file not shown.

0 comments on commit cb75c3b

Please sign in to comment.