fixed bug
This commit is contained in:
1 parent
7dcfcf7889
commit
aabbc74a06
2 files changed
+23
-4
No files matched your search
@@ -275,6 +275,18 @@ describe("question 9", function(){
|
||||
assert.equal(expt, document.getElementById("result-box-4").innerText)
|
||||
});
|
||||
|
||||
it("should remove negative numbers when computing the sum", async function() {
|
||||
const expt = 2.6 + 0 + 4.5 + 0;
|
||||
document.getElementById("input-1").value = 2.6;
|
||||
document.getElementById("input-2").value = -90;
|
||||
document.getElementById("input-3").value = 4.5;
|
||||
document.getElementById("input-4").value = -7;
|
||||
|
||||
document.getElementById("button-8").click();
|
||||
await sleep(100);
|
||||
assert.equal(expt, document.getElementById("result-box-4").innerText)
|
||||
});
|
||||
|
||||
it("should compute correctly when no values", async function() {
|
||||
const expt = 0;
|
||||
document.getElementById("input-1").value = "";
|
||||
|
||||
+11
-4
@@ -126,11 +126,18 @@ function parseFloatOr0(userInput) {
|
||||
return parseFloatOrDefault(userInput, 0);
|
||||
}
|
||||
|
||||
function valueOrZeroIfNegative(value){
|
||||
if(value < 0){
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function getMessageForExo9(userInput1, userInput2, userInput3, userInput4) {
|
||||
return parseFloatOr0(userInput1)
|
||||
+ parseFloatOr0(userInput2)
|
||||
+ parseFloatOr0(userInput3)
|
||||
+ parseFloatOr0(userInput4);
|
||||
return valueOrZeroIfNegative(parseFloatOr0(userInput1))
|
||||
+ valueOrZeroIfNegative(parseFloatOr0(userInput2))
|
||||
+ valueOrZeroIfNegative(parseFloatOr0(userInput3))
|
||||
+ valueOrZeroIfNegative(parseFloatOr0(userInput4));
|
||||
}
|
||||
|
||||
function exo9() {
|
||||
|
||||
Reference in new issue
Block a user