fix(curriculum): allow positive numbers only for decimal to binary conversion (#54708)

This commit is contained in:
Anne Deepa Prasanna
2024-05-23 00:51:47 +05:30
committed by GitHub
parent 7700a4f450
commit e70ef2a03f
99 changed files with 484 additions and 212 deletions

View File

@@ -13,6 +13,9 @@ All of the HTML and CSS for this project has been provided for you.
When you're ready to get started, use the `.getElementById()` method to get the input element with the id `number-input`, and store it in a variable called `numberInput`. Use the same method to get the button element with the id `convert-btn` and store it in a variable called `convertBtn`, and the `h2` element with the id `result` and store it in a variable called `result`.
**NOTE**: This project will only convert positive numbers into binary.
# --hints--
You should use the `document.getElementById()` method to get the `#number-input` element.

View File

@@ -19,12 +19,21 @@ isNaN("3.5"); // false
Update the second condition in your `if` statement to use the `isNaN()` function to check if the value returned by `parseInt()` is `NaN`.
# --hints--
You should wrap the value returned by `parseInt()` in the `isNaN()` function.
Also,as we mentioned in step 1 that we are considering only positive numbers, we should add a third condition in `if` statement to check whether the number is less than 0 (i.e negative numbers)
```js
assert.match(String(checkUserInput), /if\s*\(\s*!\s*numberInput\s*\.\s*value\s*\|\|\s*isNaN\(\s*parseInt\(\s*numberInput\s*\.\s*value\s*\)\s*\)\s*\)\s*\{/);
6 < 0; // false
-1 < 0; // true
-8 < 0; // true
0 < 0; //false
```
# --hints--
You should wrap the value returned by `parseInt()` in the `isNaN()` function. And add a third condition which checks the value returned by `parseInt()` to be less than 0.
```js
assert.match(String(checkUserInput), /if\s*\(\s*!\s*numberInput\s*\.\s*value\s*\|\|\s*isNaN\(\s*parseInt\(\s*numberInput\s*\.\s*value\s*\)\s*\)\s*\|\|\s*parseInt\(\s*numberInput\s*\.\s*value\s*\)\s*\<\s*0\s*\)\s*\{/);
```
The body of your `if` statement within `checkUserInput` should be empty.

View File

@@ -9,7 +9,7 @@ dashedName: step-13
Now you can alert the user if they don't enter a number, or the number is invalid before you attempt to convert it into binary.
In the body of the `if` statement, use the `alert()` method to display the text `Please provide a decimal number`.
In the body of the `if` statement, use the `alert()` method to display the text `Please provide a decimal number greater than or equal to 0`.
Note that `alert()` is a method on the `window` object in the browser, so you can use either `window.alert()` or `alert()`.
@@ -21,7 +21,7 @@ You should call the `alert()` method within the body of your `if` statement with
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(window\s*.)?\s*alert\(/);
```
When there is a falsy value in the `#number-input` element and the `checkUserInput()` function is called, the `alert()` method should display the text `Please provide a decimal number`.
When there is a falsy value in the `#number-input` element and the `checkUserInput()` function is called, the `alert()` method should display the text `Please provide a decimal number greater than or equal to 0`.
```js
const numberInput = document.getElementById("number-input");
@@ -31,7 +31,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store
numberInput.value = '';
checkUserInput();
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number');
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0');
```
# --seed--
@@ -162,7 +162,11 @@ const convertBtn = document.getElementById("convert-btn");
const result = document.getElementById("result");
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
--fcc-editable-region--
--fcc-editable-region--

View File

@@ -16,7 +16,7 @@ Add the `return` keyword after `alert()`.
You should use the `return` keyword after `alert()`.
```js
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(window\s*.)?\s*alert\(\s*('|"|`)please provide a decimal number\2\s*\)\s*;?\s*return\s*;?\s*\}/i);
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(window\s*.)?\s*alert\(\s*('|"|`)please provide a decimal number greater than or equal to 0\2\s*\)\s*;?\s*return\s*;?\s*\}/i);
```
# --seed--
@@ -147,10 +147,14 @@ const convertBtn = document.getElementById("convert-btn");
const result = document.getElementById("result");
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
--fcc-editable-region--
alert("Please provide a decimal number");
alert("Please provide a decimal number greater than or equal to 0");
--fcc-editable-region--
}

View File

@@ -163,8 +163,12 @@ const result = document.getElementById("result");
--fcc-editable-region--
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -161,8 +161,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -163,8 +163,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -184,8 +184,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -176,8 +176,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -191,8 +191,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -176,8 +176,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -173,8 +173,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -161,8 +161,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -161,8 +161,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -174,8 +174,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -167,8 +167,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -163,8 +163,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -155,8 +155,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -180,8 +180,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -167,8 +167,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -172,8 +172,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -194,8 +194,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -185,8 +185,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -157,7 +157,6 @@ const decimalToBinary = (input) => {
--fcc-editable-region--
if (input === 0) {
}
--fcc-editable-region--
@@ -179,8 +178,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -196,8 +196,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -151,8 +151,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -159,8 +159,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -163,8 +163,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -173,8 +173,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -168,8 +168,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -158,8 +158,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -158,8 +158,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -168,8 +168,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -172,8 +172,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -178,8 +178,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -178,8 +178,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -169,8 +169,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -164,7 +164,6 @@ const countdown = (number) => {
if (number === 0) {
return;
} else {
}
--fcc-editable-region--
};
@@ -185,8 +184,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -174,8 +174,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -194,8 +194,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -176,8 +176,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -186,8 +186,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -175,8 +175,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -188,8 +188,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -176,8 +176,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -191,8 +191,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -191,8 +191,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -194,8 +194,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -193,8 +193,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -196,8 +196,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -193,8 +193,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -191,8 +191,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -182,8 +182,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -196,8 +196,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -178,8 +178,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -162,8 +162,12 @@ const decimalToBinary = (input) => {
--fcc-editable-region--
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -161,8 +161,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -165,8 +165,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -165,8 +165,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -165,8 +165,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -159,8 +159,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -173,8 +173,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -180,8 +180,12 @@ const decimalToBinary = (input) => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -167,8 +167,12 @@ const decimalToBinary = (input) => {
--fcc-editable-region--
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -177,8 +177,12 @@ const showAnimation = () => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -163,8 +163,12 @@ const showAnimation = () => {
};
const checkUserInput = () => {
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -177,8 +177,12 @@ const checkUserInput = () => {
--fcc-editable-region--
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -11,16 +11,16 @@ Replace all instances of `parseInt(numberInput.value)` with `inputInt`.
# --hints--
You should replace `isNaN(parseInt(numberInput.value))` with `isNaN(inputInt)`.
You should replace `isNaN(parseInt(numberInput.value))` with `isNaN(inputInt)` and `parseInt(numberInput.value) < 0` with `inputInt < 0`.
```js
assert.notMatch(
String(checkUserInput),
/isNaN\(\s*parseInt\(\s*numberInput\s*\.\s*value\s*\)\s*\)/
/isNaN\(\s*parseInt\(\s*numberInput\s*\.\s*value\s*\)\s*\)\s*\|\|s*\(\s*parseInt\(\s*numberInput\s*\.\s*value\s*\)\s*\<\s*0/
);
assert.match(
String(checkUserInput),
/isNaN\(\s*inputInt\s*\)/
/isNaN\(\s*inputInt\s*\)\s*\|\|\s*inputInt\s*\<\s*0/
);
```
@@ -202,8 +202,12 @@ const checkUserInput = () => {
--fcc-editable-region--
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
alert("Please provide a decimal number");
if (
!numberInput.value ||
isNaN(parseInt(numberInput.value)) ||
parseInt(numberInput.value) < 0
) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -175,8 +175,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -193,8 +193,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -199,8 +199,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -199,8 +199,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -179,8 +179,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -230,8 +230,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -220,8 +220,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -223,8 +223,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -193,8 +193,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -190,8 +190,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -193,8 +193,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -203,8 +203,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -7,7 +7,7 @@ dashedName: step-92
# --description--
Then, use the compound assignment operator (`+=`) to set the `innerHTML` property of the `animationContainer` to an empty template literal string.
Then, use the compound assignment operator (`+=`) to set the `innerHTML` property of the `animationContainer` to an empty template literal string.
# --hints--
@@ -185,8 +185,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -195,8 +195,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -197,8 +197,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -190,8 +190,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -201,8 +201,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -199,8 +199,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -192,8 +192,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -13,8 +13,6 @@ Add the property `msg` to the animation object at the top of the stack, and set
# --hints--
You should add the property `msg` to the animation object at the top of the stack.
```js
@@ -206,8 +204,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -208,8 +208,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -222,8 +222,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -248,8 +248,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -251,8 +251,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -223,8 +223,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -207,8 +207,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -216,8 +216,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -227,8 +227,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -220,8 +220,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -233,8 +233,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}

View File

@@ -215,8 +215,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}
@@ -427,8 +427,8 @@ const showAnimation = () => {
const checkUserInput = () => {
const inputInt = parseInt(numberInput.value);
if (!numberInput.value || isNaN(inputInt)) {
alert("Please provide a decimal number");
if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
}