This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (' '). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dogYears = 20; | |
let earlyYears = 2; | |
earlyYears *= 10.5; | |
let laterYears = dogYears-2; | |
laterYears *= 4; | |
let dogYearsInHumanYears = earlyYears+laterYears | |
console.log(dogYearsInHumanYears); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
OlderNewer