renamed homework

This commit is contained in:
didier amyot committed 2023-11-06 07:03:41 -05:00
1 parent 4c57e476b1
commit 924444788e
4 files changed

No files matched your search

+588
View File
@@ -0,0 +1,588 @@
import mocha from "https://esm.sh/mocha@10.2.0"
import {assert} from "https://esm.sh/chai@4.3.10"
mocha.setup('bdd');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
describe("question 1", function(){
it("should have proper title", function(){
const expt = "Les Bases De La Programmation";
assert.equal(expt, document.getElementById("main-title").innerText)
})
});
describe("question 2", function(){
it("should copy a random text", async function() {
const expt = "toto";
document.getElementById("input-1").value = expt;
document.getElementById("button-1").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should copy an empty text", async function() {
const expt = "";
document.getElementById("input-1").value = expt;
document.getElementById("button-1").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
});
describe("question 3", function(){
it("should mark when input starts with letter a", async function() {
const expt = "input-2 commence par la lettre 'a'";
document.getElementById("input-2").value = "a la la";
document.getElementById("button-2").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-2").innerText)
});
it("should mark when input does not starts with letter a", async function() {
const expt = "input-2 ne commence pas par la lettre 'a'";
document.getElementById("input-2").value = "o lo lo";
document.getElementById("button-2").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-2").innerText)
});
});
describe("question 4", function(){
it("should mark when input-2 < input-3", async function() {
const expt = "input-2 < input-3";
document.getElementById("input-2").value = "allo";
document.getElementById("input-3").value = "bonjour";
document.getElementById("button-3").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
it("should mark when input-2 == input-3", async function() {
const expt = "input-2 >= input-3";
document.getElementById("input-2").value = "allo";
document.getElementById("input-3").value = "lila";
document.getElementById("button-3").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
it("should mark when input-2 > input-3", async function() {
const expt = "input-2 >= input-3";
document.getElementById("input-2").value = "bonjour";
document.getElementById("input-3").value = "allo";
document.getElementById("button-3").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
});
describe("question 5", function(){
it("should mark when all equals", async function() {
const expt = "Tout est pareil";
document.getElementById("input-1").value = "privet";
document.getElementById("input-2").value = "privet";
document.getElementById("input-3").value = "privet";
document.getElementById("input-4").value = "privet";
document.getElementById("button-4").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
it("should mark when not all equals", async function() {
const expt = "Rien n'est pareil";
document.getElementById("input-1").value = "privet";
document.getElementById("input-2").value = "";
document.getElementById("input-3").value = "privet";
document.getElementById("input-4").value = "privet";
document.getElementById("button-4").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
});
describe("question 6", function(){
it("should compute correctly when number", async function() {
const n = 5.5
const expt = (n - 32) * 1.8;
document.getElementById("input-1").value = n;
document.getElementById("button-5").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should compute correctly when number (second point)", async function() {
const n = 10
const expt = (n - 32) * 1.8;
document.getElementById("input-1").value = n;
document.getElementById("button-5").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should error message when input not a number", async function() {
const expt = "impossible de calculer";
document.getElementById("input-1").value = "hello";
document.getElementById("button-5").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should error message when input empty", async function() {
const expt = "impossible de calculer";
document.getElementById("input-1").value = "";
document.getElementById("button-5").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
});
describe("question 7", function(){
it("should compute correctly when positive number", async function() {
const n = 5.5
const expt = 5.5;
document.getElementById("input-2").value = n;
document.getElementById("button-6").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-2").innerText)
});
it("should compute correctly when negative number", async function() {
const n = -5.5
const expt = 5.5;
document.getElementById("input-2").value = n;
document.getElementById("button-6").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-2").innerText)
});
it("should error message when input not a number", async function() {
const expt = "impossible de calculer";
document.getElementById("input-2").value = "ceci n'est pas un nombre";
document.getElementById("button-6").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-2").innerText)
});
it("should error message when input empty", async function() {
const expt = "impossible de calculer";
document.getElementById("input-2").value = "";
document.getElementById("button-6").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-2").innerText)
});
});
describe("question 8", function(){
it("should compute correctly when all numbers", async function() {
const expt = 2 * 3 * 4 * 5;
document.getElementById("input-1").value = 2;
document.getElementById("input-2").value = 3;
document.getElementById("input-3").value = 4;
document.getElementById("input-4").value = 5;
document.getElementById("button-7").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
it("should compute correctly when some numbers", async function() {
const expt = 2 * 1 * 4 * 1;
document.getElementById("input-1").value = 2;
document.getElementById("input-2").value = "gizz";
document.getElementById("input-3").value = 4;
document.getElementById("input-4").value = "eezzz";
document.getElementById("button-7").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
it("should compute correctly when floats", async function() {
const expt = 2.6 * 1 * 4.5 * 1;
document.getElementById("input-1").value = 2.6;
document.getElementById("input-2").value = "gizz";
document.getElementById("input-3").value = 4.5;
document.getElementById("input-4").value = "eezzz";
document.getElementById("button-7").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
it("should compute correctly with zeros", async function() {
const expt = 2 * 3 * 0 * 5;
document.getElementById("input-1").value = 2;
document.getElementById("input-2").value = 0;
document.getElementById("input-3").value = 3;
document.getElementById("input-4").value = 5;
document.getElementById("button-7").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
it("should compute correctly when no values", async function() {
const expt = 1;
document.getElementById("input-1").value = "";
document.getElementById("input-2").value = "gizz";
document.getElementById("input-3").value = "";
document.getElementById("input-4").value = "eezzz";
document.getElementById("button-7").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-3").innerText)
});
});
describe("question 9", function(){
it("should compute correctly when all numbers", async function() {
const expt = 2 + 3 + 4 + 5;
document.getElementById("input-1").value = 2;
document.getElementById("input-2").value = 3;
document.getElementById("input-3").value = 4;
document.getElementById("input-4").value = 5;
document.getElementById("button-8").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
it("should compute correctly when some numbers", async function() {
const expt = 2 + 0 + 4 + 0;
document.getElementById("input-1").value = 2;
document.getElementById("input-2").value = "gizz";
document.getElementById("input-3").value = 4;
document.getElementById("input-4").value = "eezzz";
document.getElementById("button-8").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
it("should compute correctly when floats", async function() {
const expt = 2.6 + 0 + 4.5 + 0;
document.getElementById("input-1").value = 2.6;
document.getElementById("input-2").value = "gizz";
document.getElementById("input-3").value = 4.5;
document.getElementById("input-4").value = "eezzz";
document.getElementById("button-8").click();
await sleep(100);
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 = "";
document.getElementById("input-2").value = "gizz";
document.getElementById("input-3").value = "";
document.getElementById("input-4").value = "eezzz";
document.getElementById("button-8").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
});
describe("question 10", function(){
it("should translate Lapin", async function() {
const expt = 'Kuniklo';
document.getElementById("input-1").value = 'Lapin';
document.getElementById("button-9").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should translate Lapinne", async function() {
const expt = 'Kuniklino';
document.getElementById("input-1").value = 'Lapinne';
document.getElementById("button-9").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should translate Ville", async function() {
const expt = 'Urbo';
document.getElementById("input-1").value = 'Ville';
document.getElementById("button-9").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should translate Téléphone Cellulaire", async function() {
const expt = 'Poŝtelefono';
document.getElementById("input-1").value = 'Téléphone Cellulaire';
document.getElementById("button-9").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should not translate empty word", async function() {
const expt = 'mot non trouvé';
document.getElementById("input-1").value = '';
document.getElementById("button-9").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
it("should not translate unknown word", async function() {
const expt = 'mot non trouvé';
document.getElementById("input-1").value = 'chauve-souris';
document.getElementById("button-9").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
});
});
describe("question 11", function() {
it("should mark all big numbers", async function () {
const expt = "Est un grand nombre";
document.getElementById("input-1").value = 2000;
document.getElementById("input-2").value = 2000;
document.getElementById("input-3").value = 2000;
document.getElementById("input-4").value = 2000;
document.getElementById("button-10").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
assert.equal(expt, document.getElementById("result-box-2").innerText)
assert.equal(expt, document.getElementById("result-box-3").innerText)
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
it("should mark small big numbers", async function () {
const expt = "Est un petit nombre";
document.getElementById("input-1").value = 500;
document.getElementById("input-2").value = 500;
document.getElementById("input-3").value = 500;
document.getElementById("input-4").value = 500;
document.getElementById("button-10").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
assert.equal(expt, document.getElementById("result-box-2").innerText)
assert.equal(expt, document.getElementById("result-box-3").innerText)
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
it("should mark all on the threshold", async function () {
const expt = "Est un grand nombre";
document.getElementById("input-1").value = 1000;
document.getElementById("input-2").value = 1000;
document.getElementById("input-3").value = 1000;
document.getElementById("input-4").value = 1000;
document.getElementById("button-10").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
assert.equal(expt, document.getElementById("result-box-2").innerText)
assert.equal(expt, document.getElementById("result-box-3").innerText)
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
it("should mark all not number", async function () {
const expt = "N'est pas un nombre";
document.getElementById("input-1").value = "gratte";
document.getElementById("input-2").value = "gratte";
document.getElementById("input-3").value = "gratte";
document.getElementById("input-4").value = "gratte";
document.getElementById("button-10").click();
await sleep(100);
assert.equal(expt, document.getElementById("result-box-1").innerText)
assert.equal(expt, document.getElementById("result-box-2").innerText)
assert.equal(expt, document.getElementById("result-box-3").innerText)
assert.equal(expt, document.getElementById("result-box-4").innerText)
});
});
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(minMessage, document.getElementById("result-box-3").innerText)
assert.equal(maxMessage, 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(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();
+139
View File
@@ -0,0 +1,139 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
</head>
<body>
<div class="container">
<div class="columns">
<div class="column">
<h1 class="title is-1" id="main-title">#main-title</h1>
</div>
</div>
<div class="columns">
<div class="column">
<div id="mocha"></div>
</div>
</div>
<div class="columns">
<div class="column">
<div class="notification is-primary" id="result-box-1">
<strong>#result-box-1</strong>
<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="column">
<div class="notification is-warning" id="result-box-2">
<strong>#result-box-2</strong>
<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="column">
<div class="notification is-primary is-light" id="result-box-3">
<strong>#result-box-3</strong>
<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="column">
<div class="notification is-warning is-light" id="result-box-4">
<strong>#result-box-4</strong>
<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
</div>
<div class="columns">
<div class="column">
<label>
#input-1
<input class="input" placeholder="Text input" type="text" id="input-1">
</label>
</div>
<div class="column">
<label>
#input-2
<input class="input" placeholder="Text input" type="text" id="input-2">
</label>
</div>
<div class="column">
<label>
#input-3
<input class="input" placeholder="Text input" type="text" id="input-3">
</label>
</div>
<div class="column">
<label>
#input-4
<input class="input" placeholder="Text input" type="text" id="input-4">
</label>
</div>
</div>
<div class="columns">
<div class="column">
<button type="button" class="button is-primary" id="button-1">#button-1</button>
</div>
<div class="column">
<button type="button" class="button is-warning" id="button-2">#button-2</button>
</div>
<div class="column">
<button type="button" class="button is-primary is-light" id="button-3">#button-3</button>
</div>
<div class="column">
<button type="button" class="button is-warning is-light" id="button-4">#button-4</button>
</div>
</div>
<div class="columns">
<div class="column">
<button type="button" class="button is-primary" id="button-5">#button-5</button>
</div>
<div class="column">
<button type="button" class="button is-warning" id="button-6">#button-6</button>
</div>
<div class="column">
<button type="button" class="button is-primary is-light" id="button-7">#button-7</button>
</div>
<div class="column">
<button type="button" class="button is-warning is-light" id="button-8">#button-8</button>
</div>
</div>
<div class="columns">
<div class="column">
<button type="button" class="button is-primary" id="button-9">#button-9</button>
</div>
<div class="column">
<button type="button" class="button is-warning" id="button-10">#button-10</button>
</div>
<div class="column">
<button type="button" class="button is-primary is-light" id="button-11">#button-11</button>
</div>
<div class="column">
<button type="button" class="button is-warning is-light" id="button-12">#button-12</button>
</div>
</div>
</div>
<script src="script.js"></script>
<script type="module" src="evaluation.mjs"></script>
</body>
</html>
+304
View File
@@ -0,0 +1,304 @@
document.getElementById("main-title").innerText = "Les Bases De La Programmation";
function exo2() {
let userInput = document.getElementById("input-1").value;
document.getElementById("result-box-1").innerText = userInput;
}
document.getElementById("button-1").onclick = exo2;
function getMessageForExo3(userInput) {
if (userInput.startsWith("a")) {
return "input-2 commence par la lettre 'a'";
}
return "input-2 ne commence pas par la lettre 'a'";
}
function exo3() {
let userInput = document.getElementById("input-2").value;
document.getElementById("result-box-2").innerText = getMessageForExo3(userInput);
}
document.getElementById("button-2").onclick = exo3;
function getMessageForExo4(userInput2, userInput3) {
if (userInput2.length < userInput3.length) {
return "input-2 < input-3";
}
return "input-2 >= input-3";
}
function exo4() {
let userInput2 = document.getElementById("input-2").value;
let userInput3 = document.getElementById("input-3").value;
document.getElementById("result-box-3").innerText = getMessageForExo4(userInput2, userInput3);
}
document.getElementById("button-3").onclick = exo4;
function allEquals(a, b, c, d) {
return a === b && b === c && c === d
}
function getMessageForExo5(userInput1, userInput2, userInput3, userInput4) {
if (allEquals(userInput1, userInput2, userInput3, userInput4)) {
return "Tout est pareil";
}
return "Rien n'est pareil";
}
function exo5() {
let userInput1 = document.getElementById("input-2").value;
let userInput2 = document.getElementById("input-2").value;
let userInput3 = document.getElementById("input-2").value;
let userInput4 = document.getElementById("input-3").value;
document.getElementById("result-box-4").innerText = getMessageForExo5(userInput1, userInput2, userInput3, userInput4);
}
document.getElementById("button-4").onclick = exo5;
function isNumber(x) {
return x !== "" && !isNaN(x);
}
function getMessageForExo6(userInput) {
if (!isNumber(userInput)) {
return "impossible de calculer";
}
return (parseFloat(userInput) - 32) * 1.8
}
function exo6() {
let userInput = document.getElementById("input-1").value;
document.getElementById("result-box-1").innerText = getMessageForExo6(userInput);
}
document.getElementById("button-5").onclick = exo6;
function getMessageForExo7(userInput) {
if (!isNumber(userInput)) {
return "impossible de calculer";
}
return Math.abs(parseFloat(userInput));
}
function exo7() {
let userInput = document.getElementById("input-2").value;
document.getElementById("result-box-2").innerText = getMessageForExo7(userInput);
}
document.getElementById("button-6").onclick = exo7;
function parseFloatOrDefault(userInput, default_) {
if (isNumber(userInput)) {
return parseFloat(userInput);
}
return default_;
}
function parseFloatOr1(userInput) {
return parseFloatOrDefault(userInput, 1);
}
function getMessageForExo8(userInput1, userInput2, userInput3, userInput4) {
return parseFloatOr1(userInput1)
* parseFloatOr1(userInput2)
* parseFloatOr1(userInput3)
* parseFloatOr1(userInput4);
}
function exo8() {
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 = getMessageForExo8(userInput1, userInput2, userInput3, userInput4);
}
document.getElementById("button-7").onclick = exo8;
function parseFloatOr0(userInput) {
return parseFloatOrDefault(userInput, 0);
}
function valueOrZeroIfNegative(value){
if(value < 0){
return 0;
}
return value;
}
function getMessageForExo9(userInput1, userInput2, userInput3, userInput4) {
return valueOrZeroIfNegative(parseFloatOr0(userInput1))
+ valueOrZeroIfNegative(parseFloatOr0(userInput2))
+ valueOrZeroIfNegative(parseFloatOr0(userInput3))
+ valueOrZeroIfNegative(parseFloatOr0(userInput4));
}
function exo9() {
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-4").innerText = getMessageForExo9(userInput1, userInput2, userInput3, userInput4);
}
document.getElementById("button-8").onclick = exo9;
function translate(word) {
if (word === 'Lapin') {
return 'Kuniklo';
}
if (word === 'Lapinne') {
return 'Kuniklino';
}
if (word === 'Téléphone Cellulaire') {
return 'Poŝtelefono';
}
if (word === 'Ville') {
return 'Urbo';
}
return 'mot non trouvé';
}
function exo10() {
let userInput = document.getElementById("input-1").value;
document.getElementById("result-box-1").innerText = translate(userInput);
}
document.getElementById("button-9").onclick = exo10;
function numberSizeMessage(userInput) {
if (!isNumber(userInput)) {
return "N'est pas un nombre";
}
if (parseFloat(userInput) >= 1000) {
return "Est un grand nombre";
}
return "Est un petit nombre";
}
function exo11() {
let userInput1 = document.getElementById("input-1").value;
document.getElementById("result-box-1").innerText = numberSizeMessage(userInput1);
let userInput2 = document.getElementById("input-2").value;
document.getElementById("result-box-2").innerText = numberSizeMessage(userInput2);
let userInput3 = document.getElementById("input-3").value;
document.getElementById("result-box-3").innerText = numberSizeMessage(userInput3);
let userInput4 = document.getElementById("input-4").value;
document.getElementById("result-box-4").innerText = numberSizeMessage(userInput4);
}
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;
+32
View File
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<!--<script src="https://unpkg.com/chai/chai.js"></script>-->
<!--<script src="https://unpkg.com/mocha/mocha.js"></script>-->
<!--<script class="mocha-init">-->
<!-- mocha.setup('bdd');-->
<!-- mocha.checkLeaks();-->
<!--</script>-->
<script type="module">
import mocha from "https://esm.sh/mocha@10.2.0"
import {assert} from "https://esm.sh/chai@4.3.10"
mocha.setup('bdd');
it('should add to numbers from an es module', () => {
assert.equal(1 + 1, 2);
});
mocha.run();
</script>
</body>
</html>