-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (38 loc) · 1.1 KB
/
script.js
File metadata and controls
44 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$(document).ready(function(){
//Variables declared
var quote, author, link;
//Function declaration
function getQuote(){
var url= "https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";
//API call using Json GET method
$.getJSON(url, function(data){
console.log("Bijaya's codepen");
console.log(typeof data);
console.log("Type of data");
console.log(data);
quote = data.quoteText;
author = data.quoteAuthor;
link = data.quoteLink;
if (data.quoteAuthor) {
author = data.quoteAuthor;
} else {
author = "Anonymous";
}
$(".link").html("");
$(".quote").html('"'+quote+'"');
$(".author").html("-"+author);
$(".link").append(`
<a href="${link}">${link}</a>`
)
});
};
$("#tweet").on("click", function(){
window.open("https://twitter.com/intent/tweet?text="+quote+" - "+author);
});
$(".facebook").on("click", function(){
window.open("https://www.facebook.com/sharer/sharer.php?u="+ link);
});
$("#newQuote").on("click", function(){
getQuote();
});
});