Skip to content

Commit

Permalink
Scientific notation support & error typing
Browse files Browse the repository at this point in the history
  • Loading branch information
lawfulstupid committed Dec 23, 2024
1 parent 285e025 commit 0ce5ae4
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,29 @@
<script>
function getName() {
var input = document.getElementById('input').value;
var number = 0;
var output = document.getElementById('output');
try {
number = BigInt(input);
var number = convert(input);
output.innerHTML = nameInt(number);
} catch (e) {
console.error(e);
output.innerHTML = 'not a number';
return;
if (e instanceof SyntaxError) {
output.innerHTML = 'not a number';
} else if (e instanceof RangeError) {
output.innerHTML = 'not an integer';
} else {
output.innerHTML = 'error';
}
}
}
function convert(str) {
if (str === '') throw SyntaxError('no input');
try {
output.innerHTML = nameInt(number);
return BigInt(str);
} catch (e) {
console.error(e);
output.innerHTML = 'error';
var num = Number(str);
if (isNaN(num)) throw e;
return BigInt(Number(str));
}
}
document.getElementById('input').addEventListener('keypress', event => {
Expand Down

0 comments on commit 0ce5ae4

Please sign in to comment.