Skip to content

Commit b404c31

Browse files
committed
added javascript code
1 parent 90fe3c9 commit b404c31

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

Quote Generator/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Quote Generator</title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
12+
<div class="container">
13+
14+
<div id="quotes">
15+
Everything in life is luck.
16+
</div>
17+
<div id="author">
18+
By Donald Trump
19+
</div>
20+
<button onclick="getQuotes()">New Quotes</button>
21+
22+
</div>
23+
24+
25+
<script src="script.js">
26+
27+
</script>
28+
</body>
29+
</html>

Quote Generator/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
const quotes= document.getElementById('quotes');
3+
const author = document.getElementById('author');
4+
let jsonData = " ";
5+
let quoteData = " ";
6+
7+
const randomNo = ()=>{
8+
let randNum = Math.floor(Math.random() *1680);
9+
console.log(randNum);
10+
quoteData = jsonData[randNum];
11+
quotes.innerText = `${quoteData.text}`;
12+
// author.innerText = `${quoteData.author}`;
13+
14+
quoteData.author == null
15+
?(author.innerText = "By unKnown")
16+
:(author.innerText =`By ${quoteData.author}`);
17+
18+
}
19+
const getQuotes = async()=>{
20+
const api = "https://type.fit/api/quotes";
21+
try {
22+
let data = await fetch(api);
23+
jsonData = await data.json();
24+
// console.log(jsonData[0]);
25+
randomNo();
26+
}catch(error){
27+
console.log(error.message);
28+
}
29+
30+
}
31+
32+

Quote Generator/style.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
.container{
8+
width: 50%;
9+
height: 300px;
10+
margin: 0 auto;
11+
background-color: #1DA1F2;
12+
border-radius: 10px;
13+
display: flex;
14+
flex-direction: column;
15+
justify-content: center;
16+
align-items: center;
17+
padding: 0 80px;
18+
box-shadow: 0px 2px 8px rgba(0,0,0,0.6);
19+
}
20+
21+
#quotes{
22+
text-align: center;
23+
}
124

0 commit comments

Comments
 (0)