/*
* Functions - Exercise
*
* 1. Create a closure that returns a function that accepts msg and limit. The returned
* function will alert the msg, but only up to the limit times
* 2. Using the provided convert() function below, use .bind() to create new functions that
* can convert various units, like celcius to fahrenheit, miles to kilometers, etc
* 3. Use an IIFE make the provided function output the numbers in the order expected
*/
function createWarn(msg, limit) {
var a = 0;
// var b = msg
return function(){
if(a <= limit)
{
console.log(msg, a);
a++;
}
};
}
var warn = createWarn("You have been warned : ", 3);
// 1. closure here
warn(); // 'You have been warned 1 time'
warn(); // 'You have been warned 2 times'
warn(); // 'You have been warned 3 times'
warn(); // noop
// 2. bind here
function convert(factor, offset, input) {
return (input + (offset || 0)) * factor;
}
var fn = convert.bind(null,);
// 3. IIFE here
for (var i = 1; i <= 5; i++) {
setTimeout(function() {
console.log(i);
}, i * 1000);
}
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.