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 / 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) {
@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 / 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 / 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 / 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 / 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]);
}
/* 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 / 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 +
@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 / 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;