When you've completed all exercises, email a .js
file with all your answers to [email protected].
Write a function yell
that takes a string and console logs that string in all caps.
var yell = function (string) {
// TODO
}
Write a function addFive
such that the following code works:
var addFive = function (x) {
// TODO
}
console.log("addFive(3) should be 8:", addFive(3));
console.log("addFive(6) should be 11:", addFive(6));
Write a function divideBy
such that the following code works:
var divideBy = ???? // TODO
var result = divideBy(50, 2);
console.log('Result should be 25:', result);
result = divideBy(40, 10);
console.log('Result should be 4:', result);
result = divideBy(99, 3);
console.log('Result should be 33:', result);
Fix the following code (1 syntax error) so that the function returns 'SLAP'
:
var slap = function {
return 'SLAP';
};
slap();
Fix the following code (1 syntax error) so that the function runs:
var poke = function (name) {
return name ' reproaches your behavior.';
};
poke('Billy');
Fix the following code (2 logic errors) so that the function returns a sensible message:
var doubleIt = function (x) {
return X + ' times two is ' + x;
};
doubleIt(8);
Fix the following code (1 logic error) so that the function runs:
var greet = function () {
return "Welcome, " + name;
};
greet('Bob');
Fix the following code (1 syntax error, 1 logic error) so that the function runs:
var poke = fuction () {
console.log('ow');
};
poke;
Fix the following code (1 syntax error, 1 logic error) so that the code alert the correct message:
var askify = function (request) {
"Can you please " request + "?";
};
var result = askify('fix me');
console.log('Result should be "Can you please fix me?":', result);
Fix the following code (2 syntax errors) so that the function runs:
var multiplyString = function (string, times) {
if (times === 0) {
return '';
}
else {
return string + multiplyString(string times - 1);
}
};
var result = multiplyString('Mike' 5);
console.log(result);
Write a JavaScript program that prompts the user for a number:
- If the number is divisible by 7, alert a lucky message
- If the number is even, alert that they are an even steven.
Write a JavaScript program that prompts the user for a password of your choice:
- If correct, it alerts an access granted message
- If not correct, it alerts an access denied message
- Only allow the user to try up to three times.
Write a JavaScript program that prompts three times, and then shows a single alert with all three strings in the opposite order they were prompted.
Write a function welcome
that:
- Takes two parameters
name1
andname2
- If two parameters are present, returns "Welcome, #{name1} and #{name2}!"
- If only one parameter is present, returns "Welcome, #{name1}!"
Remember JavaScript does not have string interprolation, so you can't just use "#{name1}".
var welcome = ???? // TODO
var result = welcome('Alice', 'Bob');
console.log('Result should be "Welcome, Alice and Bob!"', result);
var result = welcome('Alice');
console.log('Result should be "Welcome, Alice!"', result);