Skip to content

Instantly share code, notes, and snippets.

View Vincent-gv's full-sized avatar

Vincent-gv

View GitHub Profile
/* Take a phrase like 'turpentine and turtles' and translate it into its "whale talk" equivalent: 'UUEEIEEAUUEE'.
There are a few simple rules for translating text to whale language:
There are no consonants. Only vowels excluding "y".
The u's and e's are extra long, so we must double them in our program.
Once we have converted text to the whale language, the result is sung slowly, as is a custom in the ocean.
https://www.codecademy.com/courses/introduction-to-javascript/projects/whale-talk?action=resume_content_item
*/
@Vincent-gv
Vincent-gv / nestedLoops.js
Last active November 5, 2018 22:12
Boucles imbriqués pour comparer deux tableaux
// Extract the names of the followers who exist in both lists.
let bobsFollowers = ['Joe', 'Marta', 'Sam', 'Erin'];
let tinasFollowers = ['Sam', 'Marta', 'Elle'];
let mutualFollowers = [];
for (let i = 0; i < bobsFollowers.length; i++) {
for (let j = 0; j < tinasFollowers.length; j++) {
if (bobsFollowers[i] === tinasFollowers[j]) {
mutualFollowers.push(bobsFollowers[i]);
}
@Vincent-gv
Vincent-gv / Array.js
Created November 5, 2018 18:43
Manipuler un tableau
let secretMessage = ['Learning', 'is', 'not', 'about', 'what', 'you', 'get', 'easily', 'the', 'first', 'time,', 'it', 'is', 'about', 'what', 'you', 'can', 'figure', 'out.', '-2015,', 'Chris', 'Pine,', 'Learn', 'JavaScript'];
secretMessage.pop(); // remove last element
secretMessage.push('to','Program'); // add the words to and Program as separate strings to the end of the array
secretMessage[7]='right'; // Change the word easily to the word right
secretMessage.shift(); // remove the first string of the array.
secretMessage.unshift('Programming'); // add the string Programming to the beginning of the array
secretMessage.splice(6, 5, 'know,'); // remove the strings get, right, the, first, time,, and replace them with the single string know,
console.log(secretMessage.join(' ')); // print the secret message as a sentence and put space between element (' ').
@Vincent-gv
Vincent-gv / TrainingDays.js
Created November 5, 2018 11:40
Training Days
const getRandEvent = () => {
const random = Math.floor(Math.random() * 3);
if (random === 0) {
return 'Marathon';
} else if (random === 1) {
return 'Triathlon';
} else if (random === 2) {
return 'Pentathlon';
}
};
@Vincent-gv
Vincent-gv / SleepDebtCalculator.js
Last active November 5, 2018 11:44
Sleep Debt Calculator
const getSleepHours = day => {
if (day === 'lundi') {return 8;}
if (day === 'mardi') {return 7;}
if (day === 'mercredi') {return 6;}
if (day === 'jeudi') {return 5;}
if (day === 'vendredi') {return 10;}
if (day === 'samedi') {return 9;}
if (day === 'dimanche') {return 13;}
};
@Vincent-gv
Vincent-gv / RockPaperScissors.js
Last active July 6, 2021 19:38
Rock, Paper, or Scissors
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput==='rock' || userInput==='paper' || userInput==='scissors') {
return userInput;
}
else {
console.log('Mauvais choix !')
}
};
@Vincent-gv
Vincent-gv / RaceDay.js
Last active November 5, 2018 11:46
Race Day
let raceNumber = Math.floor(Math.random() * 1000);
const registeredEarly = true;
const age = 19;
if (age>18 && registeredEarly) {
raceNumber+=1000
};
if (age>18 && registeredEarly) {
console.log(`You will race at 9:30 am with number ${raceNumber}.`)
}
else if (age>18 && !registeredEarly) {