├── .env.example ├── .gitignore ├── .vscode ├── github-markdown.css ├── settings.json └── spellchecker.json ├── Gemfile ├── Gemfile.lock ├── README.md ├── SUMMARY.md ├── _config.yml ├── _layouts └── default.html ├── assets ├── css │ ├── default.css │ └── style.css └── javascript │ └── anchor-js │ └── anchor.min.js ├── book.json ├── exercices ├── 1-solutions │ ├── 1-quel-type.js │ ├── 2-creation-variables.js │ ├── 3-chatbot1.js │ ├── 4-chatbot2-arbre.jpg │ └── 4-chatbot2-code.js ├── 10-composants │ ├── README.md │ ├── docs │ │ ├── accordeon.html │ │ ├── carousel.html │ │ └── videos.html │ ├── index.html │ ├── lib │ │ ├── accordeon-v1.css │ │ ├── accordeon-v1.js │ │ ├── accordeon.css │ │ ├── accordeon.js │ │ ├── carousel-v1.css │ │ ├── carousel-v1.js │ │ ├── carousel.css │ │ ├── carousel.js │ │ ├── videos-v1.css │ │ ├── videos-v1.js │ │ ├── videos.css │ │ └── videos.js │ ├── samples │ │ ├── accordeon-v1.html │ │ ├── accordeon.html │ │ ├── carousel-v1.html │ │ ├── carousel.html │ │ ├── videos-v1.html │ │ └── videos.html │ └── test.html ├── 14-ajax2 │ ├── server │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── google-auth.js │ │ ├── nitrous-post-create.sh │ │ ├── nitrous.json │ │ ├── nitrous.readme.md │ │ ├── package.json │ │ ├── public │ │ │ ├── client-ajax.html │ │ │ ├── client-ajax.js │ │ │ ├── client.html │ │ │ └── index.html │ │ └── server.js │ ├── solution │ │ └── jsbin.yisari.2.html │ └── squelette │ │ └── jsbin.bucilir.6.html ├── 2-solutions │ ├── 1-fizzbuzz.js │ ├── 2-devine.js │ ├── 3-fonctions.js │ ├── 4-chifoumi-phase-1.js │ └── 4-chifoumi-phase-2.js ├── 3-solutions │ ├── 1-calendrier.js │ ├── 2-epicerie.js │ ├── 3-pendu-bonus.js │ ├── 3-pendu.js │ ├── 4-annuaire.js │ └── 5-repertoire.js ├── 4-solutions │ ├── JS-FORM-1 │ │ ├── index.html │ │ └── index.js │ ├── bonjour.html │ ├── bonjour.js │ ├── calculatrice-bonus │ │ ├── index.html │ │ └── index.js │ └── calculatrice │ │ ├── index.html │ │ └── index.js ├── 5-solutions │ └── produits │ │ ├── index.html │ │ └── index.js ├── 6-solutions │ ├── accordeon-v2-doc.html │ ├── accordeon-v2-example.html │ ├── accordeon-v2.css │ ├── accordeon-v2.js │ ├── accordeon.css │ ├── accordeon.html │ ├── accordeon.js │ ├── carousel-v2-doc.html │ ├── carousel-v2-example.html │ ├── carousel-v2.css │ ├── carousel-v2.js │ ├── carousel.css │ ├── carousel.html │ ├── carousel.js │ ├── videos-v2-doc.html │ ├── videos-v2-example.html │ ├── videos-v2.css │ ├── videos-v2.js │ ├── videos.css │ ├── videos.html │ └── videos.js ├── 8-solutions │ ├── ajax-get-images-flickr.html │ ├── ajax-get-images-giphy.html │ ├── ajax-get-ip.js │ ├── ajax-get-time.js │ ├── ajax-get-weather.html │ ├── ajax-get-weather.js │ └── ajax-post-twitter.html └── 9-code │ ├── jsbin.haxeqad.2.html │ └── jsbin.tuyofec.5.html ├── icon.png ├── img ├── 4-1-accordion.gif ├── 4-2-carousel.gif ├── 4-3-videos.gif ├── ajax.svg ├── apple-calculator-landscape.jpg ├── arbre-decision.png ├── buttons.png ├── categories.gif ├── chrome-console.png ├── composant-multi-avec-api.png ├── composant-multi-groupe.png ├── cookbook.gif ├── diagram.svg ├── doesnotcompute.jpg ├── error-oper.png ├── error-prog.png ├── geoloc.gif ├── isnotjava.png ├── jsconsole.png ├── netscape.jpg └── screenshot.jpg ├── js-logo.png ├── package-lock.json ├── package.json ├── qcms ├── js-controle-1-solutions.pdf ├── js-controle-2-solutions.pdf ├── js-controle-3-solutions.pdf ├── js-partiel-1-solutions.pdf ├── js-test-1-solutions.pdf ├── js-test-2-solutions.pdf ├── js-test-3-solutions.pdf ├── js-test-4-solutions.pdf ├── js-test-5-solutions.pdf ├── js-test-6-solutions.pdf ├── js-test-7-solutions.pdf ├── js-test-8-solutions.pdf ├── js-test-9-solutions.pdf └── qcm-10-solutions.pdf ├── slides ├── .vscode │ └── spellchecker.json ├── 01-intro │ ├── img │ │ ├── apple-calculator-landscape.jpg │ │ ├── chrome-console.png │ │ ├── isnotjava.png │ │ ├── netscape.jpg │ │ └── yoda.png │ ├── index.html │ └── slides.md ├── 02-conditions │ ├── img │ │ └── arbre-decision.png │ ├── index.html │ └── slides.md ├── 03-algo │ ├── index.html │ └── slides.md ├── 05-fonctions │ ├── img │ │ ├── fct-appel-valeurs.png │ │ ├── fct-appel.png │ │ └── fct-chaine.png │ ├── index.html │ └── slides.md ├── 06-tableaux │ ├── index.html │ └── slides.md ├── 07-objets │ ├── index.html │ └── slides.md ├── 08-dom │ ├── index.html │ └── slides.md ├── 09-styling │ ├── img │ │ └── categories.gif │ ├── index.html │ └── slides.md ├── 10-composants │ ├── img │ │ ├── 1-accordion.gif │ │ ├── 2-carousel.gif │ │ └── 3-videos.gif │ ├── index.html │ └── slides.md ├── 11-poo │ ├── index.html │ └── slides.md ├── 12-advdom │ ├── index.html │ └── slides.md ├── 13-ajax │ ├── ajax.svg │ ├── index.html │ └── slides.md ├── 14-ajax2 │ ├── diagram-get.svg │ ├── diagram-post.svg │ ├── index.html │ └── slides.md ├── 15-auth │ ├── img │ │ ├── buttons.png │ │ ├── diagram.svg │ │ ├── screenshot.jpg │ │ └── thumbs-up.jpg │ ├── index.html │ └── slides.md ├── 16-jquery │ ├── img │ │ ├── dom-tree.png │ │ ├── dom.png │ │ └── jquery.svg │ ├── index.html │ └── slides.md ├── 17-error │ ├── img │ │ ├── error-oper.png │ │ ├── error-prog.png │ │ └── geoloc.gif │ ├── index.html │ └── slides.md ├── remark-styling.css └── remark.min.js ├── tp01.md ├── tp02.md ├── tp03.md ├── tp04.md ├── tp05.md ├── tp06.md ├── tp07.md ├── tp08.md ├── tp09.md ├── tp10.md ├── tp11.md ├── tp12.md ├── tp13.md ├── tp14.md ├── tp15.md ├── tp16.md └── tp17.md /.env.example: -------------------------------------------------------------------------------- 1 | # Create a token from https://github.com/settings/tokens 2 | # with just access to public repos, then paste it below, 3 | # and save this file as `.env` 4 | JEKYLL_GITHUB_TOKEN="xxx" 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node rules: 2 | ## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 3 | .grunt 4 | 5 | ## Dependency directory 6 | ## Commenting this out is preferred by some people, see 7 | ## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git 8 | node_modules 9 | 10 | # Book build output 11 | _book 12 | 13 | # eBook build output 14 | *.epub 15 | *.mobi 16 | /*.pdf 17 | 18 | # Jekyll / GitHub pages 19 | _site 20 | .jekyll-metadata 21 | 22 | # Other 23 | .env 24 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "markdown.styles": [ 3 | "./.vscode/github-markdown.css" 4 | ], 5 | "cSpell.language": ",fr" 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/spellchecker.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "fr", 3 | "ignoreWordsList": [ 4 | "closure", 5 | "Surbrillance", 6 | "spoilers", 7 | "Généricité", 8 | "ajax" 9 | ], 10 | "documentTypes": [ 11 | "markdown", 12 | "latex", 13 | "plaintext" 14 | ], 15 | "ignoreRegExp": [], 16 | "ignoreFileExtensions": [], 17 | "checkInterval": 5000 18 | } -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # for Jekyll, static md to html file generation 2 | # see https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/#step-2-install-jekyll-using-bundler 3 | source 'https://rubygems.org' 4 | gem 'dotenv' 5 | gem 'github-pages', group: :jekyll_plugins 6 | gem 'jekyll-seo-tag' 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | # Cours JavaScript 4 | 5 | * [TP 1 - Les Bases](tp01.md) 6 | * [TP 2 - Conditions](tp02.md) 7 | * [TP 3 - Algorithmes et Jeux](tp03.md) 8 | * [TP 4 - Fonctions](tp04.md) 9 | * [TP 5 - Tableaux](tp05.md) 10 | * [TP 6 - Objets](tp06.md) 11 | * [TP 7 - Classes et POO](tp07.md) 12 | * [TP 8 - Manipuler le Web avec DOM](tp08.md) 13 | * [TP 9 - Manipuler les classes et styles CSS](tp09.md) 14 | * [TP 10 - Manipulation DOM avancée](tp10.md) 15 | * [TP 11 - Récupération de données avec AJAX](tp11.md) 16 | * [TP 12 - Envoi de données avec AJAX](tp12.md) 17 | * [TP 13 - Composants Web](tp13.md) 18 | * [TP 14 - Composants et POO](tp14.md) 19 | * [TP 15 - jQuery, Node.js et frameworks](tp15.md) 20 | * [TP 16 - Identification avec Google et Facebook](tp16.md) 21 | * [TP 17 - Gestion d'erreurs et Geolocation API](tp17.md) 22 | 23 | 47 | 48 | ## Ressources alternatives 49 | 50 | - [Formation JavaScript de Grafikart](https://www.grafikart.fr/formations/debuter-javascript) 51 | - [(Cours/TP) Apprentissage JavaScript](https://docs.google.com/document/d/1j9KsH-YtlYuMhmcPRlqtNJ_JdrD2JUiErmwEUTWt23I), par Julien Guézennec 52 | - OpenClassrooms: [Apprenez à coder avec JavaScript](https://openclassrooms.com/courses/apprenez-a-coder-avec-javascript) 53 | - OpenClassrooms: [Créez des pages web interactives avec JavaScript](https://openclassrooms.com/courses/creez-des-pages-web-interactives-avec-javascript) 54 | - Khan Academy: [HTML/JS : faire des pages Web interactives](https://fr.khanacademy.org/computing/computer-programming/html-css-js) 55 | 56 | ## Ressources alternatives en langue anglaise 57 | 58 | - [JS for cats](http://jsforcats.com/), une explication simple et amusante des concepts de base 59 | - [You-Dont-Know-JS](https://github.com/getify/You-Dont-Know-JS/), free book series on JavaScript 60 | - [JS Books](http://jsbooks.revolunet.com/) 61 | - [JavaScript basics](https://medium.freecodecamp.com/my-giant-javascript-basics-course-is-now-live-on-youtube-and-its-100-free-9020a21bbc27), videos by Beau Carnes + [challenges on freeCampCode](http://beta.freecodecamp.com/en/map) 62 | - [JavaScript 30 — Build 30 things with vanilla JS in 30 days with 30 tutorials](https://javascript30.com/) 63 | - [leonardomso/33-js-concepts: 📜 33 concepts every JavaScript developer should know.](https://github.com/leonardomso/33-js-concepts) 64 | - [The JavaScript Bits You Skipped the First Time Around - Illustrated Notes](https://illustrated.dev/advancedjs) 65 | - [A Fruitful Guide to JavaScript's Comparison Operators - A Visual Explanation](https://illustrated.dev/fruit-comparison) 66 | - [🔥🕺🏼 JavaScript Visualized: Hoisting - DEV Community 👩💻👨💻](https://dev.to/lydiahallie/javascript-visualized-hoisting-478h) 67 | 68 | ## Ressources annexes au cours 69 | 70 | - [Apprendre à apprendre: deux modes d’apprentissage](http://www.internetactu.net/2015/09/08/apprendre-a-apprendre-14-deux-modes-dapprentissage/) 71 | - [Startup Noob Guide](http://bit.ly/startupnoob) 72 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [Introduction](README.md) 4 | * [TP 1 - Les Bases](tp01.md) 5 | * [TP 2 - Conditions](tp02.md) 6 | * [TP 3 - Algorithmes et Jeux](tp03.md) 7 | * [TP 4 - Fonctions](tp04.md) 8 | * [TP 5 - Tableaux](tp05.md) 9 | * [TP 6 - Objets](tp06.md) 10 | * [TP 7 - Classes et POO](tp07.md) 11 | * [TP 8 - Manipuler le Web avec DOM](tp08.md) 12 | * [TP 9 - Manipuler les classes et styles CSS](tp09.md) 13 | * [TP 10 - Manipulation DOM avancée](tp10.md) 14 | * [TP 11 - Récupération de données avec AJAX](tp11.md) 15 | * [TP 12 - Envoi de données avec AJAX](tp12.md) 16 | * [TP 13 - Composants Web](tp13.md) 17 | * [TP 14 - Composants et POO](tp14.md) 18 | * [TP 15 - jQuery, Node.js et frameworks](tp15.md) 19 | * [TP 16 - Identification avec Google et Facebook](tp16.md) 20 | * [TP 17 - Gestion d'erreurs et Geolocation API](tp17.md) 21 | 22 | 29 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | title: # Name of your blog (this will show up at the top of your page and in the RSS feed) 2 | Cours JavaScript 3 | 4 | author: # Your name, as you want it to appear underneath each post and in the footer 5 | Adrien Joly 6 | 7 | avatar: # URL of your avatar or profile pic (you could use your GitHub profile pic) 8 | /icon.png 9 | 10 | desc: 11 | Supports de cours JavaScript pour étudiants EEMI de 1ère année. 12 | 13 | keywords: javascript,initiation,exercices,cours,tuto,web,développement,dom 14 | 15 | repository: adrienjoly/cours-javascript 16 | 17 | google_analytics: UA-1858235-4 18 | 19 | twitter: # used by the jekyll seo plugin 20 | username: adrienjoly 21 | card: summary 22 | 23 | social: 24 | name: Adrien Joly 25 | links: 26 | - https://twitter.com/adrienjoly 27 | - https://www.linkedin.com/in/adrienjoly 28 | - https://github.com/adrienjoly 29 | - https://medium.com/@adrienjoly 30 | 31 | defaults: 32 | - scope: 33 | path: "" 34 | values: 35 | image: "/js-logo.png" 36 | author: "@adrienjoly" 37 | 38 | # github defaults 39 | encoding: UTF-8 40 | lang: fr-FR 41 | kramdown: 42 | input: GFM 43 | hard_wrap: false 44 | future: true 45 | jailed: false 46 | theme: jekyll-theme-primer 47 | gfm_quirks: paragraph_end 48 | 49 | # additional config 50 | exclude: 51 | - node_modules 52 | - "**/node_modules" 53 | - Gemfile 54 | - Gemfile.lock 55 | - src 56 | 57 | plugins: 58 | - jekyll-seo-tag 59 | -------------------------------------------------------------------------------- /_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | {% seo %} 9 | 10 | 11 | 12 | 22 | 23 | 24 |next
, et placez tous ces éléments à l'intérieur d'un élément portant la classe carousel
, de la manière suivante:
30 | carousel
, au moment où la dépendance carousel.js
sera chargée.
48 | initialiseGalerieVideo()
en passant en paramètres une référence de cet élément, et un tableau d'URLs de vidéos Youtube sous la forme https://www.youtube.com/embed/0uaQMxBjd5E
. (cf documentation d'API ci-dessous)
43 |
44 |
45 |
46 |
47 | initialiseGalerieVideo(conteneur, videos)
Cette fonction permet d'intégrer une galerie vidéo à l'intérieur de l'élément conteneur
(qui doit exister dans la page au moment de l'appel).
Au moment de l'appel, la fonction va ajouter un bouton par vidéo, afin de permettre à l'utilisateur de choisir la vidéo à consulter.
54 | 55 |Paramètres:
56 |conteneur
: référence d'élément du DOM HTML de la pagevideos
: tableau de chaînes de caractères sous la forme https://www.youtube.com/embed/0uaQMxBjd5E
Connexion: 18 |
19 | Sign out 20 | 21 |Twittez:
22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /exercices/14-ajax2/server/public/client-ajax.js: -------------------------------------------------------------------------------- 1 | var message = document.getElementById('message'); 2 | 3 | function sendMessage() { 4 | if (message.value.length === 0) { 5 | return; 6 | } 7 | message.disabled = true; 8 | var xhr = new XMLHttpRequest(); 9 | xhr.open('POST', '/tweet'); 10 | xhr.onreadystatechange = function() { 11 | if (xhr.readyState === 4) { 12 | console.log('response:', xhr.responseText); 13 | message.disabled = false; 14 | var responseObject = JSON.parse(xhr.responseText); 15 | if (responseObject.error) { 16 | alert('Error: ' + responseObject.error); 17 | } else { 18 | console.log('Message was sent successfully :-)'); 19 | message.value = ''; 20 | message.focus(); 21 | } 22 | } 23 | }; 24 | xhr.send(JSON.stringify({ 25 | message: message.value, 26 | token: window.token, // provided by Google Auth / login on client-ajax.html 27 | })); 28 | } 29 | 30 | // the change event is emitted from the input every time the user presses ENTER 31 | document.getElementById('message').onchange = function() { 32 | console.log('user pressed ENTER'); 33 | sendMessage(); 34 | }; 35 | -------------------------------------------------------------------------------- /exercices/14-ajax2/server/public/client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 17 |Connexion: 18 |
19 | Sign out 20 | 21 |Twittez:
22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /exercices/14-ajax2/server/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |Send your tweet by sending a HTTP POST request to the /tweet
API endpoint of this server.
Example: form-based client
10 |Connexion: 21 |
22 | Sign out 23 | 24 |Twittez:
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /exercices/14-ajax2/squelette/jsbin.bucilir.6.html: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |Connexion: 21 |
22 | Sign out 23 | 24 |Twittez:
25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /exercices/2-solutions/1-fizzbuzz.js: -------------------------------------------------------------------------------- 1 | // fonctions fournies dans l'énoncé 2 | 3 | function estMultipleDeTrois(nombre) { 4 | return nombre % 3 === 0; 5 | } 6 | function estMultipleDeCinq(nombre) { 7 | return nombre % 5 === 0; 8 | } 9 | 10 | // algorithme "fizzbuzz": 11 | 12 | for(var i = 1; i < 200; i++) { 13 | if (estMultipleDeCinq(i) && estMultipleDeTrois(i)) { 14 | console.log('FizzBuzz'); 15 | } else if (estMultipleDeTrois(i)) { 16 | console.log('Fizz'); 17 | } else if (estMultipleDeCinq(i)) { 18 | console.log('Buzz'); 19 | } else { 20 | console.log(i); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /exercices/2-solutions/2-devine.js: -------------------------------------------------------------------------------- 1 | var nbTours = 10; 2 | 3 | var aleatoire = Math.round(Math.random() * 100); 4 | console.log('nombre à trouver:', aleatoire); 5 | 6 | for (var i = 0; i < nbTours; ++i) { 7 | var joueur = prompt('devinez le nombre'); 8 | if (joueur > aleatoire) { 9 | alert('Plus petit'); 10 | } else if (joueur < aleatoire) { 11 | alert('Plus grand'); 12 | } else if (joueur == aleatoire) { 13 | alert('Bravo !'); 14 | break; // sort de la boucle avant la fin 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /exercices/2-solutions/3-fonctions.js: -------------------------------------------------------------------------------- 1 | function diviserParDeux (nombre) { 2 | return nombre / 2; 3 | } 4 | 5 | function somme (nombre1, nombre2) { 6 | return nombre1 + nombre2; 7 | } 8 | 9 | function signe (nombre) { 10 | if (nombre === 0) { 11 | return 'nul'; 12 | } else if (nombre > 0) { 13 | return 'positif'; 14 | } else if (nombre < 0) { 15 | return 'négatif'; 16 | } 17 | } 18 | 19 | function factorielle (nombre) { 20 | var res = 1; 21 | for(var i = 1; i <= nombre; i++) { 22 | res = i * res; 23 | } 24 | return res; 25 | } 26 | -------------------------------------------------------------------------------- /exercices/2-solutions/4-chifoumi-phase-1.js: -------------------------------------------------------------------------------- 1 | // definition de la fonction comparer 2 | // qui renvoie le nom de l'élément gagnant, entre les deux passés en paramètres 3 | function comparer(choix1, choix2) { 4 | if (choix1 === choix2) { 5 | return 'Egalité !'; 6 | } else if (choix1 === 'pierre') { 7 | if (choix2 === 'ciseaux') { 8 | return 'pierre'; 9 | } else if (choix2 === 'feuille') { 10 | return 'feuille'; 11 | } 12 | } else if (choix1 === 'feuille') { 13 | if (choix2 === 'pierre') { 14 | return 'feuille'; 15 | } else if (choix2 === 'ciseaux') { 16 | return 'ciseaux'; 17 | } 18 | } else if (choix1 === 'ciseaux') { 19 | if (choix2 === 'pierre') { 20 | return 'pierre'; 21 | } else if (choix2 === 'feuille') { 22 | return 'ciseaux'; 23 | } 24 | } 25 | } 26 | 27 | // début de partie 28 | 29 | var choixUtilisateur = prompt('Choisissez-vous pierre, feuille, ou ciseaux ?'); 30 | 31 | var choixOrdi = Math.random(); 32 | if (choixOrdi < 0.34) { 33 | choixOrdi = 'pierre'; 34 | } else if(choixOrdi <= 0.67) { 35 | choixOrdi = 'feuille'; 36 | } else { 37 | choixOrdi = 'ciseaux'; 38 | } 39 | 40 | console.log('Ordinateur:', choixOrdi); 41 | 42 | var resultat = comparer(choixUtilisateur, choixOrdi); 43 | 44 | console.log('=> Gagnant:', resultat); 45 | 46 | -------------------------------------------------------------------------------- /exercices/2-solutions/4-chifoumi-phase-2.js: -------------------------------------------------------------------------------- 1 | // definition de la fonction comparer 2 | // qui renvoie le nom de l'élément gagnant, entre les deux passés en paramètres 3 | 4 | function comparer(choix1, choix2) { 5 | if (choix1 === choix2) { 6 | return 'Egalité !'; 7 | } else if (choix1 === 'pierre') { 8 | if (choix2 === 'ciseaux') { 9 | return 'pierre'; 10 | } else if (choix2 === 'feuille') { 11 | return 'feuille'; 12 | } 13 | } else if (choix1 === 'feuille') { 14 | if (choix2 === 'pierre') { 15 | return 'feuille'; 16 | } else if (choix2 === 'ciseaux') { 17 | return 'ciseaux'; 18 | } 19 | } else if (choix1 === 'ciseaux') { 20 | if (choix2 === 'pierre') { 21 | return 'pierre'; 22 | } else if (choix2 === 'feuille') { 23 | return 'ciseaux'; 24 | } 25 | } 26 | } 27 | 28 | // début de partie 29 | 30 | var scoreOrdi = 0; 31 | var scoreJoueur = 0; 32 | 33 | for (var manche = 0; manche < 3; manche++) { 34 | 35 | // choix aléatoire de l'ordinateur 36 | 37 | var choixOrdi = Math.random(); 38 | if (choixOrdi < 0.34) { 39 | choixOrdi = 'pierre'; 40 | } else if(choixOrdi <= 0.67) { 41 | choixOrdi = 'feuille'; 42 | } else { 43 | choixOrdi = 'ciseaux'; 44 | } 45 | 46 | console.log('Ordinateur:', choixOrdi); 47 | 48 | // choix du joueur 49 | 50 | var choixUtilisateur = prompt('Choisissez-vous pierre, feuille, ou ciseaux ?'); 51 | 52 | // déterminer qui remporte la manche 53 | 54 | var resultat = comparer(choixUtilisateur, choixOrdi); 55 | 56 | // afficher les résultats de la manche, et mettre à jour les scores 57 | 58 | if (resultat === 'Egalité !') { 59 | console.log('=> Egalité !'); 60 | } else if (resultat === choixUtilisateur) { 61 | console.log('=> Gagnant de la manche:', resultat, '(joueur)'); 62 | scoreJoueur++; 63 | } else { 64 | console.log('=> Gagnant de la manche:', resultat, '(ordi)'); 65 | scoreOrdi++; 66 | } 67 | 68 | } 69 | 70 | // afficher les résultats du jeu 71 | 72 | var message; 73 | if (scoreOrdi === scoreJoueur) { 74 | message = 'Égalité !'; 75 | } else if (scoreOrdi > scoreJoueur) { 76 | message = 'Perdu !'; 77 | } else { 78 | message = 'Gagné !'; 79 | } 80 | 81 | alert(message + ' Votre score: ' + scoreJoueur + ', ordi: ' + scoreOrdi); 82 | -------------------------------------------------------------------------------- /exercices/3-solutions/1-calendrier.js: -------------------------------------------------------------------------------- 1 | var jours = [ 'lun', '007', 'mer', 'jeu', 'ven', 'sam', 'BUG' ]; 2 | jours.pop(); 3 | console.log(jours); 4 | jours.push('dim'); 5 | jours[1] = 'mar'; 6 | console.log(jours.length); 7 | console.log(jours[2]); 8 | -------------------------------------------------------------------------------- /exercices/3-solutions/2-epicerie.js: -------------------------------------------------------------------------------- 1 | var fruits = [ 'Mangue', 'Raisin', 'Figue', 'Kiwi' ]; 2 | console.log(fruits); 3 | var reponse = prompt('quel fruit desirez vous'); 4 | var indice = fruits.indexOf(reponse); 5 | if (indice !== -1) { 6 | fruits.splice(indice, 1); 7 | console.log('ok!'); 8 | } else { 9 | alert('indisponible...'); 10 | } 11 | console.log(fruits); 12 | -------------------------------------------------------------------------------- /exercices/3-solutions/3-pendu-bonus.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var MAX_TENTATIVES = 10; 4 | var mauvaisesLettres = [ ]; // sera complété pendant le jeu 5 | var lettresAttendues = [ 'a', 'n', 'n', 'a' ]; 6 | 7 | for (; mauvaisesLettres.length < MAX_TENTATIVES && lettresAttendues.length > 0; ) { 8 | console.log('lettres à trouver:', lettresAttendues); 9 | alert('Lettres à trouver: ' + lettresAttendues.length + '. ' 10 | + 'Tentatives restantes: ' + (MAX_TENTATIVES - mauvaisesLettres.length)); 11 | var lettre = prompt('Devinez une lettre'); 12 | 13 | // tant qu'on trouve des occurrences, on continue de les supprimer une à une 14 | var trouvees = 0; 15 | for (var indice = 0; indice != -1 ;) { 16 | indice = lettresAttendues.indexOf(lettre); // cherche la prochaine occurrence de la lettre 17 | if (indice != -1) { 18 | lettresAttendues.splice(indice, 1); // retire cette occurrence de la lettre trouvée dans le tableau 19 | trouvees++; 20 | } 21 | } 22 | 23 | if (trouvees > 0) { 24 | alert('Bonne pioche ! Il y avait bien ' + trouvees + ' fois la lettre ' 25 | + lettre + ' dans le mot à trouver !'); 26 | } else { 27 | mauvaisesLettres.push(lettre); 28 | alert('Le mot à trouver ne contient pas la lettre ' + lettre + ', désolé...'); 29 | } 30 | } 31 | 32 | if (lettresAttendues.length == 0) { 33 | alert('Bravo, vous avez trouvé le mot !'); 34 | } else if (mauvaisesLettres.length == MAX_TENTATIVES) { 35 | alert('Perdu... Faites une autre partie !'); 36 | } 37 | -------------------------------------------------------------------------------- /exercices/3-solutions/3-pendu.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var MAX_TENTATIVES = 10; 4 | var mauvaisesLettres = [ ]; // sera complété pendant le jeu 5 | var lettresAttendues = [ 's', 'u', 'p', 'e', 'r' ]; 6 | 7 | for (; mauvaisesLettres.length < MAX_TENTATIVES && lettresAttendues.length > 0; ) { 8 | console.log('lettres à trouver:', lettresAttendues); 9 | alert('Lettres à trouver: ' + lettresAttendues.length + '. ' 10 | + 'Tentatives restantes: ' + (MAX_TENTATIVES - mauvaisesLettres.length)); 11 | var lettre = prompt('Devinez une lettre'); 12 | var indice = lettresAttendues.indexOf(lettre); 13 | if (indice != -1) { 14 | lettresAttendues.splice(indice, 1); // retire la 1ère occurrence de cette lettre trouvée dans le tableau 15 | alert('Bonne pioche! Continuez!'); 16 | } else { 17 | mauvaisesLettres.push(lettre); 18 | alert('Le mot à trouver ne contient pas la lettre ' + lettre + ', désolé...'); 19 | } 20 | } 21 | 22 | if (lettresAttendues.length == 0) { 23 | alert('Bravo, vous avez trouvé le mot !'); 24 | } else if (mauvaisesLettres.length == MAX_TENTATIVES) { 25 | alert('Perdu... Faites une autre partie !'); 26 | } 27 | -------------------------------------------------------------------------------- /exercices/3-solutions/4-annuaire.js: -------------------------------------------------------------------------------- 1 | var annuaire = { 2 | patricia: '06 66 66 66 66', 3 | david: '07 77 77 77 77', 4 | }; 5 | 6 | // 1. Afficher dans la console le numéro de téléphone de `patricia`, en utilisant la notation pointée sur l'objet `annuaire`; 7 | 8 | console.log(annuaire.patricia); 9 | 10 | // 2. Demander à l'utilisateur de saisir un prénom, puis afficher le numéro de téléphone associé à ce prénom. 11 | 12 | var nom = prompt('donner le nom d\'un ami'); 13 | alert('numéro de téléphone de ' + nom + ': ' + annuaire[nom]); 14 | -------------------------------------------------------------------------------- /exercices/3-solutions/5-repertoire.js: -------------------------------------------------------------------------------- 1 | var repertoire = { 2 | 'luke' : '0666666666', 3 | 'yoda' : '0688888888', 4 | }; 5 | 6 | // non demandé dans l'énoncé, juste pour vérifier le bon fonctionnement dans la console: 7 | console.log('[debug] repertoire:', repertoire); 8 | 9 | // l'utilisateur peut effectuer plusieurs opération, jusqu'à ce qu'il presse `q` 10 | for (var choix; choix != 'q';) { 11 | choix = prompt('fonction: (r)echerche, (l)iste, (a)jout, (s)uppression, ou (q)uitter ?'); 12 | if (choix === 'r') { 13 | var nom = prompt('donner le nom d\'un ami'); 14 | alert('numéro associé: ' + repertoire[nom]); 15 | } else if (choix === 'l') { 16 | for (var nom in repertoire) { 17 | console.log(nom, ':', repertoire[nom]); 18 | } 19 | } else if (choix === 'a') { 20 | var nom = prompt('donner le nom de l\'ami à ajouter'); 21 | var num = prompt('donner son numéro de téléphone'); 22 | repertoire[nom] = num; 23 | } else if (choix === 's') { 24 | var nom = prompt('donner le nom de l\'ami à supprimer du répertoire'); 25 | delete repertoire[nom]; 26 | } 27 | // non demandé dans l'énoncé, juste pour vérifier le bon fonctionnement dans la console: 28 | console.log('[debug] repertoire:', repertoire); 29 | } 30 | -------------------------------------------------------------------------------- /exercices/4-solutions/JS-FORM-1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |premier nombre:
7 | 8 | 9 |opération:
10 | 16 | 17 |deuxieme nombre:
18 | 19 | 20 | 21 | 22 |résultat:
23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /exercices/4-solutions/calculatrice-bonus/index.js: -------------------------------------------------------------------------------- 1 | document.getElementById('mon-bouton').onclick = function() { 2 | var nombre1 = parseInt(document.getElementById('premier-nombre').value); 3 | var nombre2 = parseInt(document.getElementById('deuxieme-nombre').value); 4 | var operation = document.getElementById('operation').value; 5 | var result; 6 | if (operation === '-') { 7 | result = nombre1 - nombre2; 8 | } else if (operation === '*') { 9 | result = nombre1 * nombre2; 10 | } else if (operation === '/') { 11 | result = nombre1 / nombre2; 12 | } else { 13 | result = nombre1 + nombre2; 14 | } 15 | document.getElementById('resultat').value = result; 16 | }; 17 | -------------------------------------------------------------------------------- /exercices/4-solutions/calculatrice/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |premier nombre:
7 | 8 | 9 |deuxieme nombre:
10 | 11 | 12 | 13 | 14 |résultat:
15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /exercices/4-solutions/calculatrice/index.js: -------------------------------------------------------------------------------- 1 | document.getElementById('mon-bouton').onclick = function() { 2 | var nombre1 = parseInt(document.getElementById('premier-nombre').value); 3 | var nombre2 = parseInt(document.getElementById('deuxieme-nombre').value); 4 | document.getElementById('resultat').value = nombre1 + nombre2; 5 | }; 6 | -------------------------------------------------------------------------------- /exercices/5-solutions/produits/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |next
, et placez tous ces éléments à l'intérieur d'un élément portant la classe carousel
, de la manière suivante:
30 | carousel
, au moment où la dépendance carousel.js
sera chargée.
48 | initialiseGalerieVideo()
en passant en paramètres une référence de cet élément, et un tableau d'URLs de vidéos Youtube sous la forme https://www.youtube.com/embed/0uaQMxBjd5E
. (cf documentation d'API ci-dessous)
43 |
44 |
45 |
46 |
47 | initialiseGalerieVideo(conteneur, videos)
Cette fonction permet d'intégrer une galerie vidéo à l'intérieur de l'élément conteneur
(qui doit exister dans la page au moment de l'appel).
Au moment de l'appel, la fonction va ajouter un bouton par vidéo, afin de permettre à l'utilisateur de choisir la vidéo à consulter.
54 | 55 |Paramètres:
56 |conteneur
: référence d'élément du DOM HTML de la pagevideos
: tableau de chaînes de caractères sous la forme https://www.youtube.com/embed/0uaQMxBjd5E
Connexion: 21 |
22 | Sign out 23 | 24 |Twittez:
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /exercices/9-code/jsbin.haxeqad.2.html: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 29 | 30 | 31 | 32 |Bonjour,
38 | [[ Insérer bouton de déconnexion ici ]] 39 |Bonjour,
40 |