Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exos Pierre #9

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ex01.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex01.js">
</script>
</head>
<body>

</body>
</html>
5 changes: 2 additions & 3 deletions ex01.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
qui retourne ce paramètre "nb";
*/

function returnParameter(nb) {
return nb;
}
function returnParameter(nb) {return nb;}

// écrire votre code sous ce commentaire

console.log(returnParameter(5));
13 changes: 13 additions & 0 deletions ex02.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex02.js">
</script>
</head>
<body>

</body>
</html>
3 changes: 3 additions & 0 deletions ex02.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
retParam(5);

// écrire votre code sous ce commentaire

function retParam(n){return(n);}
console.log(retParam(5));
13 changes: 13 additions & 0 deletions ex03.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex03.js">
</script>
</head>
<body>

</body>
</html>
5 changes: 4 additions & 1 deletion ex03.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Nous appelons déjà la fonction;
Vous n'avez plus qu'a coder la fonction;

Utilisez la fonction console.log
Utilisez la fonction conso le.log
pour afficher la valeur de retour de la fonction;
*/

Expand All @@ -29,3 +29,6 @@ addition(98766, 345678);

// écrire votre code sous ce commentaire

function addition(a,b) {return (a + b);}
console.log(addition(6,9));
console.log(addition(98766,34678));
13 changes: 13 additions & 0 deletions ex04.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex04.js">
</script>
</head>
<body>

</body>
</html>
5 changes: 5 additions & 0 deletions ex04.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ isEven(6);
isEven(5);

// écrire votre code sous ce commentaire

function isEven(n) { return (n % 2 == 0) ? "1" :"2";}

console.log(isEven(6));
console.log(isEven(5));
13 changes: 13 additions & 0 deletions ex05.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex05.js">
</script>
</head>
<body>

</body>
</html>
5 changes: 5 additions & 0 deletions ex05.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ isEvenConcat(6);
isEvenConcat(5);

// écrire votre code sous ce commentaire

function isEvenConcat(n){ return (n % 2 == 0)? "Le nombre " + n + " est pair et ":"le nombre " + n + " est impair.";}

console.log(isEvenConcat(6));
console.log(isEvenConcat(5));
13 changes: 13 additions & 0 deletions ex06.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex06.js">
</script>
</head>
<body>

</body>
</html>
8 changes: 8 additions & 0 deletions ex06.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ getHumanTypeByAge(33);
getHumanTypeByAge(140);

// écrire votre code sous ce commentaire

function getHumanTypeByAge (age) { return (age > 0 && age < 12)? "enfant": (age >= 12 && age < 18)? "ado":(age >= 18 && age < 124)? "adulte":"impossible";}

console.log(getHumanTypeByAge(-5));
console.log(getHumanTypeByAge(6));
console.log(getHumanTypeByAge(17));
console.log(getHumanTypeByAge(33));
console.log(getHumanTypeByAge(140));
13 changes: 13 additions & 0 deletions ex07.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex07.js">
</script>
</head>
<body>

</body>
</html>
13 changes: 13 additions & 0 deletions ex07.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ boostedAddition([4, 5, 6]);
boostedAddition([4, 4, 6, 8, 10, 12]);

// écrire votre code sous ce commentaire


function boostedAddition (table) {
let sum = 0;
for(i = 0; i < table.length; i++) {
sum = sum+table[i];
}
return sum;
}

console.log(boostedAddition([4, 5, 6]));
console.log(boostedAddition([4, 4, 6, 8, 10, 12]));

13 changes: 13 additions & 0 deletions ex08.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex08.js">
</script>
</head>
<body>

</body>
</html>
21 changes: 21 additions & 0 deletions ex08.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@ isAllEven([4, 4, 6, 8, 10, 12]);

// écrire votre code sous ce commentaire

function isEven(n) {
if (n % 2 != 0) {
return 0;
}
else {
return 1;
}
}

function isAllEven(table) {
for (let i = 0; i < table.length; i++) {
if (isEven(table[i]) != 1) {
return 0;
}
}
return 1;
}

console.log(isAllEven([4, 5, 6]));
console.log(isAllEven([4, 6, 6, 8, 10, 12]));

13 changes: 13 additions & 0 deletions ex09.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex09.js">
</script>
</head>
<body>

</body>
</html>
52 changes: 52 additions & 0 deletions ex09.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,55 @@ boostedEvenAddition([4, 5, 6]);
boostedEvenAddition([1, 3, 4, 5, 4, 6, 9, 8, 11, 10, 11, 12]);

// écrire votre code sous ce commentaire

function boostedAddition(array) {
let sum = 0;
for (i = 0; i < array.length; i++) {
sum = sum + array[i];
}
return sum;
}



function isEven(n) {
if (n % 2 != 0) {
return 0;
}
else {
return 1;
}
}

function boostedEvenAddition(table) {
var array = [];
for (let i = 0; i < table.length; i++) {
if (isEven(table[i]) == 1) {
array.push(table[i]);
}
}
return boostedAddition(array);
}





console.log(boostedEvenAddition([4, 5, 6]));
console.log(boostedEvenAddition([1, 3, 4, 5, 4, 6, 9, 8, 11, 10, 11, 12]));


// Beaucoup plus simple, méthode Stéph:

function simple(table) {
let sumpair= 0;
for (i=0; i<table.length;i++) {
if(table[i] % 2 == 0) {
sumpair = sumpair + table[i];
}
}
return sumpair;
}

console.log(simple([4, 5, 6]));
console.log(simple([1, 3, 4, 5, 4, 6, 9, 8, 11, 10, 11, 12]));
13 changes: 13 additions & 0 deletions ex10.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ex10.js">
</script>
</head>
<body>

</body>
</html>
39 changes: 39 additions & 0 deletions ex10.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,42 @@ shoppingList([
]);

// écrire votre code sous ce commentaire

function shoppingList(table) {
var kiwi= 0;
var ananas= 0;
var prune= 0;
var banane= 0;
var pamplemousse= 0;
var orange= 0;

for (let i = 0; i<table.length; i++) {
for (let j = 0; j<table[i].length; j++){

switch (table[i][j]) {
case "kiwi": kiwi++;
break;
case "ananas": ananas++;
break;
case "prune": prune++;
break;
case "banane": banane++;
break;
case "pamplemousse": pamplemousse++;
break;
case "orange": orange++;
break;
}
}
}
return "kiwi:" + kiwi + " ananas:" + ananas + " prune:" + prune + " banane:" + banane + " pamplemousse:" + pamplemousse + " orange:" + orange;
}


console.log(shoppingList([
["orange", "orange", "kiwi", "ananas"],
["kiwi", "ananas", "banane", "prune"],
["orange", "orange", "orange", "orange"],
["orange", "orange", "kiwi", "kiwi"],
["prune", "banane", "pamplemousse", "ananas"]
]));