-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
53 lines (51 loc) · 1.97 KB
/
index.html
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
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Numbers</title>
<!-- CSS only -->
<style>
#fact {
display: none;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body class="bg-dark">
<div class="container">
<div class="row">
<div class="col-md-4 mx-auto">
<div class="card bg-primary text-white mt-5 p-4">
<h1>Numbers</h1>
<p>Enter a Random Number</p>
<input type="number" class="form-control form-control-lg" id="numbertype" placeholder="Enter a number....">
<div id="fact" class="card-body px-0 py-3">
<h4 class="card-title">Fact</h4>
<p class="card-text" id="facttext"></p>
</div>
</div>
</div>
<script>
let fact = document.querySelector('#fact');
let factext = document.querySelector('#factext');
let numbertype = document.querySelector('#numbertype');
numbertype.addEventListener('input', numberinfo);
function numberinfo(){
number = numbertype.value;
const xhr = new XMLHttpRequest();
xhr.open('GET', 'http://numbersapi.com/' + number, true);
xhr.onload = function(){
if(this.status === 200 && number!=''){
console.log(this.responseText);
fact.style.display = 'block';
facttext.innerText = this.responseText;
}
};
xhr.send();
}
</script>
</body>
</html>