fixed bug

This commit is contained in:
didier amyot committed 2023-11-03 09:37:46 -04:00
1 parent 7dcfcf7889
commit aabbc74a06
2 files changed
+23 -4

No files matched your search

+12
View File
@@ -275,6 +275,18 @@ describe("question 9", function(){
assert.equal(expt, document.getElementById("result-box-4").innerText) 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() { it("should compute correctly when no values", async function() {
const expt = 0; const expt = 0;
document.getElementById("input-1").value = ""; document.getElementById("input-1").value = "";
+11 -4
View File
@@ -126,11 +126,18 @@ function parseFloatOr0(userInput) {
return parseFloatOrDefault(userInput, 0); return parseFloatOrDefault(userInput, 0);
} }
function valueOrZeroIfNegative(value){
if(value < 0){
return 0;
}
return value;
}
function getMessageForExo9(userInput1, userInput2, userInput3, userInput4) { function getMessageForExo9(userInput1, userInput2, userInput3, userInput4) {
return parseFloatOr0(userInput1) return valueOrZeroIfNegative(parseFloatOr0(userInput1))
+ parseFloatOr0(userInput2) + valueOrZeroIfNegative(parseFloatOr0(userInput2))
+ parseFloatOr0(userInput3) + valueOrZeroIfNegative(parseFloatOr0(userInput3))
+ parseFloatOr0(userInput4); + valueOrZeroIfNegative(parseFloatOr0(userInput4));
} }
function exo9() { function exo9() {