From 2034b2f56b9e88d1616d58f968ff28b875a6ab12 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Thu, 16 Nov 2023 10:52:18 -0500 Subject: [PATCH] Added correction for last homework. --- travail-pratique-3/evaluation.mjs | 78 ++++++++++++++++++++----------- travail-pratique-3/index.html | 16 +------ travail-pratique-3/script.js | 56 ++++++++++++++++------ 3 files changed, 94 insertions(+), 56 deletions(-) diff --git a/travail-pratique-3/evaluation.mjs b/travail-pratique-3/evaluation.mjs index bceb403..4d5e5c5 100644 --- a/travail-pratique-3/evaluation.mjs +++ b/travail-pratique-3/evaluation.mjs @@ -127,31 +127,31 @@ describe("question 4", function(){ }) -describe("question 6", function(){ - async function testQuestion6(userInput, expt){ - document.getElementById("input-1").value = userInput; - document.getElementById("button-5").click(); +describe("question 5", function(){ + async function testQuestion5(userInput, expt){ + document.getElementById("input-4").value = userInput; + document.getElementById("button-4").click(); await sleep(100); - assert.equal(expt, document.getElementById("result-box-1").innerText) + assert.equal(expt, document.getElementById("result-box-4").innerText) } it("should find the proper number of existing country is input by user", async function(){ - await testQuestion6("Canada", 3); + await testQuestion5("Canada", 3); }); it("should show zero when non existing country is input by user", async function(){ - await testQuestion6("France", 0); + await testQuestion5("France", 0); }); }) -describe("question 7", function(){ +describe("question 6", function(){ async function testQuestion7(userInput, expt){ - document.getElementById("input-2").value = userInput; - document.getElementById("button-6").click(); + document.getElementById("input-1").value = userInput; + document.getElementById("button-5").click(); await sleep(100); - assert.equal(expt, document.getElementById("result-box-2").innerText) + assert.equal(expt, document.getElementById("result-box-1").innerText) } it("should find the proper population of existing country is input by user", async function(){ @@ -164,6 +164,23 @@ describe("question 7", function(){ }) +describe("question 7", function(){ + async function testQuestion7(userInput, expt){ + document.getElementById("input-2").value = userInput; + document.getElementById("button-6").click(); + await sleep(100); + assert.equal(expt, document.getElementById("result-box-2").innerText) + } + + it("should find the proper city of existing country is input by user", async function(){ + await testQuestion7("Canada", "Toronto"); + }); + + it("should show zero when non existing country is input by user", async function(){ + await testQuestion7("France", "aucune ville trouvée"); + }); +}) + describe("question 8", function(){ async function testQuestion8(userInput, expt){ document.getElementById("input-3").value = userInput; @@ -172,23 +189,6 @@ describe("question 8", function(){ assert.equal(expt, document.getElementById("result-box-3").innerText) } - it("should find the proper city of existing country is input by user", async function(){ - await testQuestion8("Canada", "Toronto"); - }); - - it("should show zero when non existing country is input by user", async function(){ - await testQuestion8("France", "aucune ville trouvée"); - }); -}) - -describe("question 9", function(){ - async function testQuestion8(userInput, expt){ - document.getElementById("input-4").value = userInput; - document.getElementById("button-8").click(); - await sleep(100); - assert.equal(expt, document.getElementById("result-box-4").innerText) - } - it("should find the proper country of existing person entered by input by user", async function(){ await testQuestion8("Djaffar Bensetti", "Algerie"); }); @@ -198,5 +198,27 @@ describe("question 9", function(){ }); }) +describe("question 9", function(){ + async function testQuestion9(userInput, expt){ + document.getElementById("input-4").value = userInput; + document.getElementById("button-8").click(); + await sleep(100); + assert.equal(expt, document.getElementById("result-box-4").innerText) + } + + it("Canada", async function(){ + await testQuestion9("Canada", 3); + }); + + it("Mexique", async function(){ + await testQuestion9("Mexique", 0); + }); + + it("France", async function(){ + await testQuestion9("France", 0); + }); + +}) + mocha.run(); \ No newline at end of file diff --git a/travail-pratique-3/index.html b/travail-pratique-3/index.html index bbc98f2..c2107ae 100644 --- a/travail-pratique-3/index.html +++ b/travail-pratique-3/index.html @@ -110,20 +110,6 @@ -
-
- -
-
- -
-
- -
-
- -
-
@@ -132,4 +118,4 @@ - \ No newline at end of file + diff --git a/travail-pratique-3/script.js b/travail-pratique-3/script.js index 0bc27ee..3fa1197 100644 --- a/travail-pratique-3/script.js +++ b/travail-pratique-3/script.js @@ -116,13 +116,13 @@ function findNumberOfCitiesInCountry(countryName) { return n; } -function exo6(){ - const userInput = document.getElementById("input-1").value; - document.getElementById("result-box-1").innerText = findNumberOfCitiesInCountry(userInput); +function exo5(){ + const userInput = document.getElementById("input-4").value; + document.getElementById("result-box-4").innerText = findNumberOfCitiesInCountry(userInput); } -document.getElementById("button-5").onclick = exo6; +document.getElementById("button-4").onclick = exo5; function findPopulationOfCitiesInCountry(countryName) { @@ -135,13 +135,13 @@ function findPopulationOfCitiesInCountry(countryName) { return population; } -function exo7(){ - const userInput = document.getElementById("input-2").value; - document.getElementById("result-box-2").innerText = findPopulationOfCitiesInCountry(userInput); +function exo6(){ + const userInput = document.getElementById("input-1").value; + document.getElementById("result-box-1").innerText = findPopulationOfCitiesInCountry(userInput); } -document.getElementById("button-6").onclick = exo7; +document.getElementById("button-5").onclick = exo6; function getCitiesInCountry(country) { const ret = []; @@ -177,13 +177,13 @@ function findLargestCitiesInCountry(country){ } -function exo8(){ - const userInput = document.getElementById("input-3").value; - document.getElementById("result-box-3").innerText = findLargestCitiesInCountry(userInput); +function exo7(){ + const userInput = document.getElementById("input-2").value; + document.getElementById("result-box-2").innerText = findLargestCitiesInCountry(userInput); } -document.getElementById("button-7").onclick = exo8; +document.getElementById("button-6").onclick = exo7; function getPersonByName(personName) { @@ -212,9 +212,39 @@ function findCountryOfOrigin(personName){ } +function exo8(){ + const userInput = document.getElementById("input-3").value; + document.getElementById("result-box-3").innerText = findCountryOfOrigin(userInput); +} + + +document.getElementById("button-7").onclick = exo8; + + +function getPersonsByCityName(cityName) { + const ret = []; + for(const person of persons){ + if(person.city === cityName){ + ret.push(person); + } + } + return ret; +} + +function findAllPeopleInCountryByName(countryName) { + let ret = []; + for(const city of cities){ + if(city.country === countryName){ + ret = ret.concat(getPersonsByCityName(city.name)); + } + } + return ret; + +} + function exo9(){ const userInput = document.getElementById("input-4").value; - document.getElementById("result-box-4").innerText = findCountryOfOrigin(userInput); + document.getElementById("result-box-4").innerText = findAllPeopleInCountryByName(userInput).length; }