added correction (to almost all quesitons)
This commit is contained in:
1 parent
735389d37c
commit
c3945fff82
3 files changed
+586
-11
No files matched your search
+395
-4
@@ -5,16 +5,407 @@ mocha.setup('bdd');
|
|||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
it('should run a bogus test', () => {
|
|
||||||
assert.equal(1 + 1, 2);
|
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)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should copy text", async () => {
|
describe("question 2", function(){
|
||||||
|
it("should copy a random text", async function() {
|
||||||
const expt = "toto";
|
const expt = "toto";
|
||||||
document.getElementById("input-1").value = expt;
|
document.getElementById("input-1").value = expt;
|
||||||
document.getElementById("button-1").click();
|
document.getElementById("button-1").click();
|
||||||
await sleep(1000);
|
await sleep(100);
|
||||||
assert.equal(expt, document.getElementById("result-box-1").innerText)
|
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 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 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)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
mocha.run();
|
mocha.run();
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
|
|||||||
+189
-7
@@ -1,17 +1,199 @@
|
|||||||
|
|
||||||
|
document.getElementById("main-title").innerText = "Les Bases De La Programmation";
|
||||||
|
|
||||||
|
|
||||||
function exo1b() {
|
function exo2() {
|
||||||
let userInput = document.getElementById("input-1").value;
|
let userInput = document.getElementById("input-1").value;
|
||||||
document.getElementById("result-box-1").innerText = userInput;
|
document.getElementById("result-box-1").innerText = userInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("button-1").onclick = exo1b;
|
document.getElementById("button-1").onclick = exo2;
|
||||||
|
|
||||||
|
|
||||||
function exo1c() {
|
function getMessageForExo3(userInput) {
|
||||||
let userInput = document.getElementById("input-2").value;
|
if(userInput.startsWith("a")){
|
||||||
|
return "input-2 commence par la lettre 'a'";
|
||||||
document.getElementById("result-box-3").innerText = getExo1c;
|
}
|
||||||
|
return "input-2 ne commence pas par la lettre 'a'";
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("button-2").onclick = exo1b;
|
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 getMessageForExo9(userInput1, userInput2, userInput3, userInput4) {
|
||||||
|
return parseFloatOr0(userInput1)
|
||||||
|
+ parseFloatOr0(userInput2)
|
||||||
|
+ parseFloatOr0(userInput3)
|
||||||
|
+ 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;
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user