www.w3resource.com/javascript-exercises/javascript-basic-exercise-2.php
A Pen by Casey Burnett on CodePen.
function showName () { | |
console.log("Casey Burnett") | |
} | |
showName() |
var favouriteColor = "green"; | |
function showColor() { | |
console.log(favouriteColor); | |
} | |
showColor(); |
favouriteColor = "green"; | |
function showColor() { | |
var secondFavouriteColor = "red"; | |
console.log(favouriteColor); | |
console.log(secondFavouriteColor); | |
} | |
showColor(); | |
console.log(favouriteColor); | |
// doesn't display as local scope | |
console.log(secondFavouriteColor); |
var car = "Honda Civic"; | |
showCar(); | |
var showCar = function(){ | |
console.log(car); | |
}; | |
// Because of hoisting the function expression is hoisted prior to the assignment of the function expression. Thus the call of the showCar(); breaks . |
var car = "Honda Civic"; | |
showCar(); | |
// By making it a function declaration scope & hoisting are not an issue | |
function showCar(){ | |
console.log(car); | |
} |
var food = "pizza"; | |
function getFood(){ | |
console.log(food); //what does this line alert? | |
// Assigning var food is hoisted w/n function w/o assignment and first console.log returns undefined. Then var food is assigned saugages and returns "sausages" | |
var food = "sausages"; | |
console.log(food); // what does this line alert? | |
} |
{ | |
"added_words": | |
[ | |
"Mockup", | |
"plugins", | |
"coffeescript", | |
"sourcemaps", | |
"html", | |
"plugin", | |
"init", |
// 7. Write a JavaScript function that accepts a string as a parameter and counts the number of vowels within the string. Go to the editor | |
// Note : As the letter 'y' can be regarded as both a vowel and a consonant, we do not count 'y' as vowel here. | |
// Example string : 'The quick brown fox' | |
// Expected Output : 5 | |
((str) => console.log( | |
str.split('') | |
.reduce( | |
(prev, current) => { | |
if("aeiouAEIOU".split('').indexOf(current) != -1){ | |
return ++prev; |
A Pen by Casey Burnett on CodePen.