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 / 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 / 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 / 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;
/* 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 / 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;
@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 / 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 / funcParam.js
Created November 23, 2018 03:04
Functions as Parameters
const checkThatTwoPlusTwoEqualsFourAMillionTimes = () => {
for(let i = 1; i <= 1000000; i++) {
if ( (2 + 2) != 4) {
console.log('Something has gone very wrong :( ');
}
}
};
const addTwo = num => num + 2;
@Vincent-gv
Vincent-gv / dogYears.js
Created November 23, 2018 01:08
The first two years of a dog's life count as 10.5 dog years each. Each year following equates to 4 dog years.
const dogYears = 20;
let earlyYears = 2;
earlyYears *= 10.5;
let laterYears = dogYears-2;
laterYears *= 4;
let dogYearsInHumanYears = earlyYears+laterYears
console.log(dogYearsInHumanYears);
@Vincent-gv
Vincent-gv / temperature.js
Created November 23, 2018 00:53
Temperature conversion
// forecast today
let kelvin = 293;
let celsius = kelvin-273;
let fahrenheit = celsius*(9/5)+32;
let newton = celsius*(33/100);
// .floor() method from the Math library to round down the Fahrenheit temperature
fahrenheit = Math.floor(fahrenheit);
newton = Math.floor(newton);
celsius = Math.floor(celsius);
console.log('The temperature is '+ fahrenheit + ' degrees Fahrenheit. '+ celsius + ' degrees Celsius. ' + newton +