finished correction
This commit is contained in:
1 parent
c3945fff82
commit
7dcfcf7889
2 files changed
+292
-20
No files matched your search
+118
-20
@@ -1,4 +1,3 @@
|
||||
|
||||
document.getElementById("main-title").innerText = "Les Bases De La Programmation";
|
||||
|
||||
|
||||
@@ -11,7 +10,7 @@ document.getElementById("button-1").onclick = exo2;
|
||||
|
||||
|
||||
function getMessageForExo3(userInput) {
|
||||
if(userInput.startsWith("a")){
|
||||
if (userInput.startsWith("a")) {
|
||||
return "input-2 commence par la lettre 'a'";
|
||||
}
|
||||
return "input-2 ne commence pas par la lettre 'a'";
|
||||
@@ -26,7 +25,7 @@ document.getElementById("button-2").onclick = exo3;
|
||||
|
||||
|
||||
function getMessageForExo4(userInput2, userInput3) {
|
||||
if(userInput2.length < userInput3.length){
|
||||
if (userInput2.length < userInput3.length) {
|
||||
return "input-2 < input-3";
|
||||
}
|
||||
return "input-2 >= input-3";
|
||||
@@ -40,11 +39,12 @@ function exo4() {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
function getMessageForExo5(userInput1, userInput2, userInput3, userInput4) {
|
||||
if(allEquals(userInput1, userInput2, userInput3, userInput4)){
|
||||
if (allEquals(userInput1, userInput2, userInput3, userInput4)) {
|
||||
return "Tout est pareil";
|
||||
}
|
||||
return "Rien n'est pareil";
|
||||
@@ -60,15 +60,15 @@ function exo5() {
|
||||
|
||||
document.getElementById("button-4").onclick = exo5;
|
||||
|
||||
function isNumber(x){
|
||||
function isNumber(x) {
|
||||
return x !== "" && !isNaN(x);
|
||||
}
|
||||
|
||||
function getMessageForExo6(userInput) {
|
||||
if(!isNumber(userInput)){
|
||||
if (!isNumber(userInput)) {
|
||||
return "impossible de calculer";
|
||||
}
|
||||
return (parseFloat(userInput) -32) * 1.8
|
||||
return (parseFloat(userInput) - 32) * 1.8
|
||||
}
|
||||
|
||||
function exo6() {
|
||||
@@ -80,7 +80,7 @@ document.getElementById("button-5").onclick = exo6;
|
||||
|
||||
|
||||
function getMessageForExo7(userInput) {
|
||||
if(!isNumber(userInput)){
|
||||
if (!isNumber(userInput)) {
|
||||
return "impossible de calculer";
|
||||
}
|
||||
return Math.abs(parseFloat(userInput));
|
||||
@@ -94,7 +94,7 @@ function exo7() {
|
||||
document.getElementById("button-6").onclick = exo7;
|
||||
|
||||
function parseFloatOrDefault(userInput, default_) {
|
||||
if(isNumber(userInput)){
|
||||
if (isNumber(userInput)) {
|
||||
return parseFloat(userInput);
|
||||
}
|
||||
return default_;
|
||||
@@ -122,7 +122,6 @@ function exo8() {
|
||||
document.getElementById("button-7").onclick = exo8;
|
||||
|
||||
|
||||
|
||||
function parseFloatOr0(userInput) {
|
||||
return parseFloatOrDefault(userInput, 0);
|
||||
}
|
||||
@@ -145,17 +144,17 @@ function exo9() {
|
||||
document.getElementById("button-8").onclick = exo9;
|
||||
|
||||
|
||||
function translate(word){
|
||||
if(word === 'Lapin'){
|
||||
function translate(word) {
|
||||
if (word === 'Lapin') {
|
||||
return 'Kuniklo';
|
||||
}
|
||||
if(word === 'Lapinne'){
|
||||
if (word === 'Lapinne') {
|
||||
return 'Kuniklino';
|
||||
}
|
||||
if(word === 'Téléphone Cellulaire'){
|
||||
if (word === 'Téléphone Cellulaire') {
|
||||
return 'Poŝtelefono';
|
||||
}
|
||||
if(word === 'Ville'){
|
||||
if (word === 'Ville') {
|
||||
return 'Urbo';
|
||||
}
|
||||
return 'mot non trouvé';
|
||||
@@ -169,12 +168,11 @@ function exo10() {
|
||||
document.getElementById("button-9").onclick = exo10;
|
||||
|
||||
|
||||
|
||||
function numberSizeMessage(userInput){
|
||||
if(!isNumber(userInput)){
|
||||
function numberSizeMessage(userInput) {
|
||||
if (!isNumber(userInput)) {
|
||||
return "N'est pas un nombre";
|
||||
}
|
||||
if(parseFloat(userInput) >= 1000){
|
||||
if (parseFloat(userInput) >= 1000) {
|
||||
return "Est un grand nombre";
|
||||
}
|
||||
return "Est un petit nombre";
|
||||
@@ -197,3 +195,103 @@ function 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