finished correction
This commit is contained in:
1 parent
c3945fff82
commit
7dcfcf7889
2 files changed
+275
-3
No files matched your search
@@ -407,5 +407,179 @@ describe("question 11", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("question 12", function() {
|
||||||
|
|
||||||
|
it("should mark when sorted numbers", async function () {
|
||||||
|
const expt = "les données sont ordonnées";
|
||||||
|
document.getElementById("input-1").value = 1;
|
||||||
|
document.getElementById("input-2").value = 2;
|
||||||
|
document.getElementById("input-3").value = 3;
|
||||||
|
document.getElementById("input-4").value = 4;
|
||||||
|
|
||||||
|
document.getElementById("button-11").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(expt, document.getElementById("result-box-3").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should mark when sorted numbers (2)", async function () {
|
||||||
|
const expt = "les données sont ordonnées";
|
||||||
|
document.getElementById("input-1").value = 1;
|
||||||
|
document.getElementById("input-2").value = 1;
|
||||||
|
document.getElementById("input-3").value = 2;
|
||||||
|
document.getElementById("input-4").value = 2;
|
||||||
|
|
||||||
|
document.getElementById("button-11").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(expt, document.getElementById("result-box-3").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should mark when not a number", async function () {
|
||||||
|
const expt = "les données ne sont pas ordonnées";
|
||||||
|
document.getElementById("input-1").value = 1;
|
||||||
|
document.getElementById("input-2").value = 1;
|
||||||
|
document.getElementById("input-3").value = 2;
|
||||||
|
document.getElementById("input-4").value = "hello";
|
||||||
|
|
||||||
|
document.getElementById("button-11").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(expt, document.getElementById("result-box-3").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should mark when no numbers", async function () {
|
||||||
|
const expt = "les données ne sont pas ordonnées";
|
||||||
|
document.getElementById("input-1").value = "a";
|
||||||
|
document.getElementById("input-2").value = "b";
|
||||||
|
document.getElementById("input-3").value = "c";
|
||||||
|
document.getElementById("input-4").value = "e";
|
||||||
|
|
||||||
|
document.getElementById("button-11").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(expt, document.getElementById("result-box-3").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("question 13", function() {
|
||||||
|
|
||||||
|
it("should work as expected (1)", async function () {
|
||||||
|
const minMessage = "Minima";
|
||||||
|
const maxMessage = "Maxima";
|
||||||
|
const noMinOrMaxMessage = "Ni minima, ni maxima";
|
||||||
|
const noNumberMessage = "Pas un nombre";
|
||||||
|
document.getElementById("input-1").value = 1;
|
||||||
|
document.getElementById("input-2").value = 2;
|
||||||
|
document.getElementById("input-3").value = 3;
|
||||||
|
document.getElementById("input-4").value = 4;
|
||||||
|
|
||||||
|
document.getElementById("button-12").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-1").innerText)
|
||||||
|
assert.equal(noMinOrMaxMessage, document.getElementById("result-box-2").innerText)
|
||||||
|
assert.equal(noMinOrMaxMessage, document.getElementById("result-box-3").innerText)
|
||||||
|
assert.equal(maxMessage, document.getElementById("result-box-4").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work as expected (2)", async function () {
|
||||||
|
const minMessage = "Minima";
|
||||||
|
const maxMessage = "Maxima";
|
||||||
|
const noMinOrMaxMessage = "Ni minima, ni maxima";
|
||||||
|
const noNumberMessage = "Pas un nombre";
|
||||||
|
document.getElementById("input-1").value = 1;
|
||||||
|
document.getElementById("input-2").value = 2;
|
||||||
|
document.getElementById("input-3").value = 1;
|
||||||
|
document.getElementById("input-4").value = 2;
|
||||||
|
|
||||||
|
document.getElementById("button-12").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-1").innerText)
|
||||||
|
assert.equal(maxMessage, document.getElementById("result-box-2").innerText)
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-3").innerText)
|
||||||
|
assert.equal(maxMessage, document.getElementById("result-box-4").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work as expected (3)", async function () {
|
||||||
|
const minMessage = "Minima";
|
||||||
|
const maxMessage = "Maxima";
|
||||||
|
const noMinOrMaxMessage = "Ni minima, ni maxima";
|
||||||
|
const noNumberMessage = "Pas un nombre";
|
||||||
|
document.getElementById("input-1").value = 1;
|
||||||
|
document.getElementById("input-2").value = "ramallah";
|
||||||
|
document.getElementById("input-3").value = 1;
|
||||||
|
document.getElementById("input-4").value = 2;
|
||||||
|
|
||||||
|
document.getElementById("button-12").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-1").innerText)
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-2").innerText)
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-3").innerText)
|
||||||
|
assert.equal(maxMessage, document.getElementById("result-box-4").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work as expected (4)", async function () {
|
||||||
|
const minMessage = "Minima";
|
||||||
|
const maxMessage = "Maxima";
|
||||||
|
const noMinOrMaxMessage = "Ni minima, ni maxima";
|
||||||
|
const noNumberMessage = "Pas un nombre";
|
||||||
|
document.getElementById("input-1").value = "";
|
||||||
|
document.getElementById("input-2").value = "";
|
||||||
|
document.getElementById("input-3").value = "";
|
||||||
|
document.getElementById("input-4").value ="";
|
||||||
|
|
||||||
|
document.getElementById("button-12").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-1").innerText)
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-2").innerText)
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-3").innerText)
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-4").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work as expected (5)", async function () {
|
||||||
|
const minMessage = "Minima";
|
||||||
|
const maxMessage = "Maxima";
|
||||||
|
const noMinOrMaxMessage = "Ni minima, ni maxima";
|
||||||
|
const noNumberMessage = "Pas un nombre";
|
||||||
|
document.getElementById("input-1").value = 5;
|
||||||
|
document.getElementById("input-2").value = "";
|
||||||
|
document.getElementById("input-3").value = "";
|
||||||
|
document.getElementById("input-4").value = 1;
|
||||||
|
|
||||||
|
document.getElementById("button-12").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(maxMessage, document.getElementById("result-box-1").innerText)
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-2").innerText)
|
||||||
|
assert.equal(noNumberMessage, document.getElementById("result-box-3").innerText)
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-4").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work as expected (6)", async function () {
|
||||||
|
const minMessage = "Minima";
|
||||||
|
const maxMessage = "Maxima";
|
||||||
|
const noMinOrMaxMessage = "Ni minima, ni maxima";
|
||||||
|
const noNumberMessage = "Pas un nombre";
|
||||||
|
document.getElementById("input-1").value = 5;
|
||||||
|
document.getElementById("input-2").value = 5;
|
||||||
|
document.getElementById("input-3").value = 5;
|
||||||
|
document.getElementById("input-4").value = 5;
|
||||||
|
|
||||||
|
document.getElementById("button-12").click();
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-1").innerText)
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-2").innerText)
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-3").innerText)
|
||||||
|
assert.equal(minMessage, document.getElementById("result-box-4").innerText)
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
mocha.run();
|
mocha.run();
|
||||||
+101
-3
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
document.getElementById("main-title").innerText = "Les Bases De La Programmation";
|
document.getElementById("main-title").innerText = "Les Bases De La Programmation";
|
||||||
|
|
||||||
|
|
||||||
@@ -43,6 +42,7 @@ document.getElementById("button-3").onclick = exo4;
|
|||||||
function allEquals(a, b, c, d) {
|
function allEquals(a, b, c, d) {
|
||||||
return a === b && b === c && c === d
|
return a === b && b === c && c === d
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMessageForExo5(userInput1, userInput2, userInput3, userInput4) {
|
function getMessageForExo5(userInput1, userInput2, userInput3, userInput4) {
|
||||||
if (allEquals(userInput1, userInput2, userInput3, userInput4)) {
|
if (allEquals(userInput1, userInput2, userInput3, userInput4)) {
|
||||||
return "Tout est pareil";
|
return "Tout est pareil";
|
||||||
@@ -122,7 +122,6 @@ function exo8() {
|
|||||||
document.getElementById("button-7").onclick = exo8;
|
document.getElementById("button-7").onclick = exo8;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function parseFloatOr0(userInput) {
|
function parseFloatOr0(userInput) {
|
||||||
return parseFloatOrDefault(userInput, 0);
|
return parseFloatOrDefault(userInput, 0);
|
||||||
}
|
}
|
||||||
@@ -169,7 +168,6 @@ function exo10() {
|
|||||||
document.getElementById("button-9").onclick = exo10;
|
document.getElementById("button-9").onclick = exo10;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function numberSizeMessage(userInput) {
|
function numberSizeMessage(userInput) {
|
||||||
if (!isNumber(userInput)) {
|
if (!isNumber(userInput)) {
|
||||||
return "N'est pas un nombre";
|
return "N'est pas un nombre";
|
||||||
@@ -197,3 +195,103 @@ function exo11() {
|
|||||||
document.getElementById("button-10").onclick = exo11;
|
document.getElementById("button-10").onclick = exo11;
|
||||||
|
|
||||||
|
|
||||||
|
function allNumbers(userInput1, userInput2, userInput3, userInput4) {
|
||||||
|
return isNumber(userInput1)
|
||||||
|
&& isNumber(userInput2)
|
||||||
|
&& isNumber(userInput3)
|
||||||
|
&& isNumber(userInput4);
|
||||||
|
}
|
||||||
|
|
||||||
|
function areSorted(number, number2, number3, number4) {
|
||||||
|
return number <= number2 && number2 <= number3 && number3 <= number4;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessageForExo12(userInput1, userInput2, userInput3, userInput4) {
|
||||||
|
if (!allNumbers(userInput1, userInput2, userInput3, userInput4)) {
|
||||||
|
return "les données ne sont pas ordonnées";
|
||||||
|
}
|
||||||
|
const areAllSorted = areSorted(parseFloat(userInput1),
|
||||||
|
parseFloat(userInput2),
|
||||||
|
parseFloat(userInput3),
|
||||||
|
parseFloat(userInput4));
|
||||||
|
if(!areAllSorted){
|
||||||
|
return "les données ne sont pas ordonnées";
|
||||||
|
}
|
||||||
|
return "les données sont ordonnées";
|
||||||
|
}
|
||||||
|
|
||||||
|
function exo12() {
|
||||||
|
let userInput1 = document.getElementById("input-1").value;
|
||||||
|
let userInput2 = document.getElementById("input-2").value;
|
||||||
|
let userInput3 = document.getElementById("input-3").value;
|
||||||
|
let userInput4 = document.getElementById("input-4").value;
|
||||||
|
document.getElementById("result-box-3").innerText = getMessageForExo12(userInput1, userInput2, userInput3, userInput4);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("button-11").onclick = exo12;
|
||||||
|
|
||||||
|
|
||||||
|
function getMinNumericalValue(userInput1, userInput2, userInput3, userInput4) {
|
||||||
|
let minValue = 99999999999999;
|
||||||
|
if(isNumber(userInput1) && parseFloat(userInput1) < minValue){
|
||||||
|
minValue = parseFloat(userInput1);
|
||||||
|
}
|
||||||
|
if(isNumber(userInput2) && parseFloat(userInput2) < minValue){
|
||||||
|
minValue = parseFloat(userInput2);
|
||||||
|
}
|
||||||
|
if(isNumber(userInput3) && parseFloat(userInput3) < minValue){
|
||||||
|
minValue = parseFloat(userInput3);
|
||||||
|
}
|
||||||
|
if(isNumber(userInput4) && parseFloat(userInput4) < minValue){
|
||||||
|
minValue = parseFloat(userInput4);
|
||||||
|
}
|
||||||
|
return minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMaxNumericalValue(userInput1, userInput2, userInput3, userInput4) {
|
||||||
|
let maxValue = -99999999999999;
|
||||||
|
if(isNumber(userInput1) && parseFloat(userInput1) > maxValue){
|
||||||
|
maxValue = parseFloat(userInput1);
|
||||||
|
}
|
||||||
|
if(isNumber(userInput2) && parseFloat(userInput2) > maxValue){
|
||||||
|
maxValue = parseFloat(userInput2);
|
||||||
|
}
|
||||||
|
if(isNumber(userInput3) && parseFloat(userInput3) > maxValue){
|
||||||
|
maxValue = parseFloat(userInput3);
|
||||||
|
}
|
||||||
|
if(isNumber(userInput4) && parseFloat(userInput4) > maxValue){
|
||||||
|
maxValue = parseFloat(userInput4);
|
||||||
|
}
|
||||||
|
return maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMinMaxMessage(userInput, minValue, maxValue){
|
||||||
|
if(!isNumber(userInput)){
|
||||||
|
return "Pas un nombre";
|
||||||
|
}
|
||||||
|
if(parseFloat(userInput) === minValue){
|
||||||
|
return "Minima";
|
||||||
|
}
|
||||||
|
if(parseFloat(userInput) === maxValue){
|
||||||
|
return "Maxima";
|
||||||
|
}
|
||||||
|
return "Ni minima, ni maxima";
|
||||||
|
}
|
||||||
|
|
||||||
|
function exo13() {
|
||||||
|
let userInput1 = document.getElementById("input-1").value;
|
||||||
|
let userInput2 = document.getElementById("input-2").value;
|
||||||
|
let userInput3 = document.getElementById("input-3").value;
|
||||||
|
let userInput4 = document.getElementById("input-4").value;
|
||||||
|
const minValue = getMinNumericalValue(userInput1, userInput2, userInput3, userInput4);
|
||||||
|
const maxValue = getMaxNumericalValue(userInput1, userInput2, userInput3, userInput4);
|
||||||
|
|
||||||
|
|
||||||
|
document.getElementById("result-box-1").innerText = getMinMaxMessage(userInput1, minValue, maxValue);
|
||||||
|
document.getElementById("result-box-2").innerText = getMinMaxMessage(userInput2, minValue, maxValue);
|
||||||
|
document.getElementById("result-box-3").innerText = getMinMaxMessage(userInput3, minValue, maxValue);
|
||||||
|
document.getElementById("result-box-4").innerText = getMinMaxMessage(userInput4, minValue, maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("button-12").onclick = exo13;
|
||||||
|
|
||||||
Reference in new issue
Block a user