Skip to content

Instantly share code, notes, and snippets.

@julia-r
Last active January 18, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julia-r/7d8eceec586cc20718854cab4fd3ef7d to your computer and use it in GitHub Desktop.
Save julia-r/7d8eceec586cc20718854cab4fd3ef7d to your computer and use it in GitHub Desktop.
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
<!-- content to be placed inside <body>…</body> -->
// Returns: Counting A... - A 1 - A 2 - A3
/* var count = function(){
console.log("Counting A...");
console.log("A 1");
console.log("A 2");
console.log("A 3");
}();*/
// Returns: Counting B... - B1 - B3 - B2
/*var count2 = function(){
console.log("Counting B...");
console.log("B1");
setTimeout(function(){ console.log("B2"); },1000);
console.log("B3");
}();*/
var count3 = function(){
console.log("Counting C...");
console.log("C1");
let myPromise = new Promise((resolve, reject) => {
setTimeout(function(){ console.log("C2.a"); resolve("C2.b"); }, 1000);
})
.then((num) => {
console.log("Yay! " + num);
console.log("C3");
});
};
//count3();
var count4 = function(){
console.log("Counting D...");
console.log("D1");
let myPromise = new Promise((resolve, reject) => {
setTimeout(function(){ console.log("D2.a"); resolve ("D2.b"); }, 1000);
})
.then((num) => {
console.log(num);
console.log("D3");
setTimeout(function(){ console.log("D4.a"); return ("D4.b"); }, 1000);
})
.then((num) => {
console.log(num);
console.log("D5");
});
};
//count4();
var count5 = function(i){
console.log("Testing...");
let myPromise = new Promise((resolve, reject) => {
if (i < 10){
resolve("Success");
}
else {
reject("Error");
}
})
.catch((value) => {
console.error("error", value);
})
.then((result) => {
console.log("then: ", result);
});
};
//count5(15)
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment