forked from thejsway/thejsway_fr-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
281 additions
and
1,103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": ["airbnb", "prettier"], | ||
"env": { | ||
"browser": true | ||
}, | ||
"plugins": ["prettier"], | ||
"rules": { | ||
"no-console": "off", | ||
"no-alert": "off", | ||
"no-plusplus": "off", | ||
"default-case": "off", | ||
"no-param-reassign": [ | ||
"error", | ||
{ | ||
"props": false | ||
} | ||
], | ||
"arrow-body-style": [ | ||
"error", | ||
"as-needed", | ||
{ "requireReturnForObjectLiteral": true } | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# Apprenez à coder avec JavaScript | ||
|
||
Code source associé au cours OpenClassrooms [Apprenez à coder avec JavaScript](https://openclassrooms.com/courses/apprenez-a-coder-avec-javascript) | ||
|
||
- Chapitre 1 : "3, 2, 1... Codez !" | ||
- Chapitre 2 : "Jouez avec les variables" | ||
- Chapitre 3 : "Ajoutez des conditions" | ||
- Chapitre 4 : "Répétez des instructions" | ||
- Chapitre 5 : "Modularisez votre code avec des fonctions" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Présentation | ||
|
||
console.log("Baptiste"); | ||
console.log(41); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Calculatrice | ||
|
||
console.log(6 + 3); // 9 | ||
console.log(6 - 3); // 3 | ||
console.log(6 * 3); // 18 | ||
console.log(6 / 3); // 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Prédiction de résultat | ||
|
||
console.log(4 + 5); // 9 | ||
console.log("4 + 5"); // "4 + 5" | ||
console.log("4" + "5"); // "45" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Prédiction de valeurs | ||
|
||
let a = 2; | ||
a -= 1; | ||
a++; | ||
let b = 8; | ||
b += 2; | ||
const c = a + b * b; | ||
const d = a * b + b; | ||
const e = a * (b + b); | ||
const f = a * b / a; | ||
const g = b / a * a; | ||
|
||
console.log(a, b, c, d, e, f, g); // 2 10 102 30 40 10 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Celsius - Fahrenheit | ||
|
||
const tempCel = 37.1; | ||
|
||
const tempFar = tempCel * 9 / 5 + 32; | ||
console.log(`${tempCel}°C = ${tempFar}°F`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Permutation de variables | ||
|
||
let nombre1 = 5; | ||
let nombre2 = 3; | ||
|
||
// Solution classique utilisant une variable temporaire | ||
const temp = nombre1; | ||
nombre1 = nombre2; | ||
nombre2 = temp; | ||
|
||
// Solution alternative valable uniquement pour des nombres | ||
/* nombre1 += nombre2; | ||
nombre2 = nombre1 - nombre2; | ||
nombre1 -= nombre2; */ | ||
|
||
console.log(nombre1); // 3 | ||
console.log(nombre2); // 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Jour suivant | ||
|
||
const jourActuel = "lundi"; | ||
let jourSuivant = ""; | ||
|
||
// Solution avec un if | ||
if (jourActuel === "lundi") { | ||
jourSuivant = "mardi"; | ||
} else if (jourActuel === "mardi") { | ||
jourSuivant = "mercredi"; | ||
} else if (jourActuel === "mercredi") { | ||
jourSuivant = "jeudi"; | ||
} else if (jourActuel === "jeudi") { | ||
jourSuivant = "vendredi"; | ||
} else if (jourActuel === "vendredi") { | ||
jourSuivant = "samedi"; | ||
} else if (jourActuel === "samedi") { | ||
jourSuivant = "dimanche"; | ||
} else if (jourActuel === "dimanche") { | ||
jourSuivant = "lundi"; | ||
} else { | ||
console.log("Erreur : jour non reconnu !"); | ||
} | ||
|
||
// Solution alternative avec un switch | ||
/* switch (jourActuel) { | ||
case "lundi": | ||
jourSuivant = "mardi"; | ||
break; | ||
case "mardi": | ||
jourSuivant = "mercredi"; | ||
break; | ||
case "mercredi": | ||
jourSuivant = "jeudi"; | ||
break; | ||
case "jeudi": | ||
jourSuivant = "vendredi"; | ||
break; | ||
case "vendredi": | ||
jourSuivant = "samedi"; | ||
break; | ||
case "samedi": | ||
jourSuivant = "dimanche"; | ||
break; | ||
case "dimanche": | ||
jourSuivant = "lundi"; | ||
break; | ||
default: | ||
console.log("Erreur : jour non reconnu !"); | ||
} */ | ||
|
||
if (jourSuivant !== "") { | ||
console.log(`Demain, nous serons ${jourSuivant}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Baccalauréat | ||
|
||
const moyenne = 11; | ||
|
||
if (moyenne < 10) { | ||
console.log("Le candidat est recalé"); | ||
} else if (moyenne < 12) { | ||
// 10 <= moyenne < 12 | ||
console.log("Le candidat est reçu"); | ||
} else { | ||
// moyenne >= 12 | ||
console.log("Le candidat est reçu avec mention"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Manège | ||
|
||
const nbTours = 10; | ||
|
||
console.log("Le manège démarre"); | ||
|
||
// Solution avec for | ||
for (let tour = 1; tour <= nbTours; tour++) { | ||
console.log(`C'est le tour numéro ${tour}`); | ||
} | ||
|
||
// Solution alternative avec un while | ||
/* let tour = 1; | ||
while (tour <= nbTours) { | ||
console.log(`C'est le tour numéro ${tour}`); | ||
tour++; | ||
} */ | ||
|
||
console.log("Le manège s'arrête"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Table de multiplication | ||
|
||
const nombre = 7; // Faites varier cette variable entre 1 et 10 | ||
|
||
console.log(`Table de multiplication de ${nombre}`); | ||
|
||
// Solution avec un for | ||
for (let i = 1; i <= 10; i++) { | ||
console.log(`${nombre} x ${i} = ${nombre * i}`); | ||
} | ||
|
||
// Solution alternative avec un while | ||
/* let i = 1; | ||
while (i <= 10) { | ||
console.log(`${nombre} x ${i} = ${nombre * i}`); | ||
i++; | ||
} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// FizzBuzz | ||
|
||
// Solution avec des if/else | ||
for (let nombre = 1; nombre <= 100; nombre++) { | ||
if (nombre % 3 === 0 && nombre % 5 === 0) console.log("FizzBuzz"); | ||
else if (nombre % 3 === 0) console.log("Fizz"); | ||
else if (nombre % 5 === 0) console.log("Buzz"); | ||
else console.log(nombre); | ||
} | ||
|
||
// Solution alternative construisant le message par concaténation | ||
/* for (let nombre = 1; nombre <= 100; nombre++) { | ||
let message = ""; // Message initial vide | ||
if (nombre % 3 === 0) { | ||
// on ajoute "Fizz" au message | ||
message += "Fizz"; | ||
} | ||
if (nombre % 5 === 0) { | ||
// on ajoute "Buzz" au message | ||
message += "Buzz"; | ||
} | ||
if (message === "") { | ||
// Message vide : on affiche le nombre | ||
message = nombre; | ||
} | ||
console.log(message); | ||
} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Carré d'un nombre | ||
|
||
// Renvoie le carré de x | ||
function carre1(x) { | ||
return x * x; | ||
} | ||
|
||
// Renvoie le carré de x | ||
const carre2 = x => x * x; | ||
|
||
console.log(carre1(0)); // 0 | ||
console.log(carre1(2)); // 4 | ||
console.log(carre1(5)); // 25 | ||
|
||
console.log(carre2(0)); // 0 | ||
console.log(carre2(2)); // 4 | ||
console.log(carre2(5)); // 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Renvoie le minimum entre a et b | ||
const min = (a, b) => { | ||
if (a < b) { | ||
return a; | ||
} | ||
return b; | ||
}; | ||
|
||
// Solution alternative avec une déclaration de fonction | ||
/* function min(a, b) { | ||
if (a < b) { | ||
return a; | ||
} | ||
return b; | ||
} */ | ||
|
||
console.log(min(4.5, 5)); // 4.5 | ||
console.log(min(19, 9)); // 9 | ||
console.log(min(1, 1)); // 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Calculatrice | ||
|
||
// Effectue les 4 opérations arithmétiques de base | ||
function calculer(nbGauche, operation, nbDroite) { | ||
let resultat; | ||
switch (operation) { | ||
case "+": | ||
resultat = nbGauche + nbDroite; | ||
break; | ||
case "-": | ||
resultat = nbGauche - nbDroite; | ||
break; | ||
case "*": | ||
resultat = nbGauche * nbDroite; | ||
break; | ||
case "/": | ||
resultat = nbGauche / nbDroite; | ||
break; | ||
} | ||
return resultat; | ||
} | ||
|
||
console.log(calculer(4, "+", 6)); // 10 | ||
console.log(calculer(4, "-", 6)); // -2 | ||
console.log(calculer(2, "*", 0)); // 0 | ||
console.log(calculer(12, "/", 0)); // Infinity |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.