Skip to content

Instantly share code, notes, and snippets.

View Vincent-gv's full-sized avatar

Vincent-gv

View GitHub Profile
@Vincent-gv
Vincent-gv / index.html
Last active November 23, 2018 13:44
reverseString.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@Vincent-gv
Vincent-gv / chiens.js
Created December 7, 2018 18:38
Modélisation de plusieurs chiens en POO
var Chien = {
init: function (nom, race, taille) {
this.nom = nom;
this.race = race;
this.taille = taille;
},
aboyer: function () {
var description = " Grrr! Grrr! ";
return description;
}
@Vincent-gv
Vincent-gv / films.js
Created December 7, 2018 23:09
Tableaux d'objets
var Film = {
// Initialise le film
init: function (titre, annee) {
this.titre = titre;
this.annee = annee;
},
// Renvoie la description du film
decrire: function () {
var description = this.titre + " (" + this.annee + ")";
return description;
/* La fenêtre de saisie se charge en 1er et n'affiche
pas le console.log tant qu'elle n'est pas validée.
Comment afficher les 2 simultanément ? */
console.log('merci de répondre à ce questionnaire');
var plat = prompt("Quel est votre plat préféré ?");
switch(plat) // debut du switch
{
case "frites":
@Vincent-gv
Vincent-gv / listeContacts.js
Last active December 8, 2018 11:41
Ajouter un contact
/*
Activité : gestion des contacts
*/
// TODO : complétez le programme
var Contact = {
// initialisation du contact
init: function (nom, prenom) {
this.prenom = prenom;
@Vincent-gv
Vincent-gv / compterCaracteres.js
Created December 8, 2018 18:56
Affiche “Vrai” si la chaîne compte autant de “x” que de “o”.
// affiche “Vrai” si la chaîne compte autant de “x” que de “o”.
var chaine = "xoxxooxoxxxoooo";
var x = 0;
var o = 0;
for (var i = 0; i < chaine.length; i++) {
if (chaine[i] === "x") {
x++;
} else if (chaine[i] === "o") {
o++;
}
@Vincent-gv
Vincent-gv / creation-liste-liens.css
Last active December 9, 2018 02:28
Création d'une liste de liens - Utilisation de l'API du DOM
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
background-color: #eee;
margin-left: 30px;
margin-right: 30px;
}
span {
font-weight: normal;
font-size: 80%;
@Vincent-gv
Vincent-gv / colors.js
Last active December 9, 2018 22:21
Changer la couleur des divs selon la touche pressée : https://oc-courses.github.io/javascript-web/chapitre_5/html/couleurs.html
/*
Changer la couleur des divs :
*/
document.addEventListener("keypress", function (e) {
var touche = String.fromCharCode(e.charCode); // Récupération de la touche pressée
touche = touche.toUpperCase(); // Pour gérer indifféremment minuscules et majuscules
var couleur = "";
switch (touche) {
case "B":
/*
Exercice : compter les clics
*/
function clic() {
compteurClics++;
document.getElementById("compteurClics").textContent = compteurClics;
}
var compteurClics = 0;
@Vincent-gv
Vincent-gv / click.js
Last active December 9, 2018 22:52
-- NOTES -- Gestion du clic souris
function clic() {
console.log("Clic !");
}
var boutonElt = document.getElementById("bouton");
// Ajout d'un gestionnaire pour l'évènement click
boutonElt.addEventListener("click", clic);
/*var boutonElt = document.getElementById("bouton");
// Ajout d'un gestionnaire pour l'évènement click