Refer to the below image.
Instructions:
- Add an id userInputto the HTMLinputelement
- Add an id factto the HTML paragraph element
Achieve the given functionality to the given prefilled code.
- When we enter number in the HTML element with the id userInputand press Enter,
- If the value of the userInputis empty, show an alert message to enter a number.
- If the value of the userInputis not empty,
- Include the value entered in the HTML inputelement with the iduserInputat the end of the URL.
- Make HTTP Request (GET method) using Fetch with URL https://apis.ccbp.in/numbers-fact?number=
- Add the loading status with the Bootstrap component spinnerwhile making HTTP request as shown in the image.
- Set HTTP response (with key fact) in the HTML paragraph element with the idfact
COPY HTML CODE From Below:
WATCH ON YOUTUBE
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous" />
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</head>
<body>
<div class="p-2 bg-container d-flex flex-column justify-content-center text-center">
<h1 class="heading">Enter a number to know interesting facts about the number</h1>
<input id="userInput" type="search" class="form-control user-input ml-auto mr-auto mt-4" placeholder="Enter a Number" />
<div class="d-none spinner" id="spinner">
<div class="d-flex flex-row justify-content-center mt-4">
<div class="spinner-border" role="status"></div>
</div>
</div>
<p id="fact" class="fact-text mt-4">0 is the atomic number of the theoretical element tetraneutron.</p>
</div>
</body>
</html>
COPY CSS CODE From Below:
@import url("https://fonts.googleapis.com/css2?family=Bree+Serif&family=Caveat:wght@400;700&family=Lobster&family=Monoton&family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&family=Playfair+Display+SC:ital,wght@0,400;0,700;1,700&family=Playfair+Display:ital,wght@0,400;0,700;1,700&family=Roboto:ital,wght@0,400;0,700;1,400;1,700&family=Source+Sans+Pro:ital,wght@0,400;0,700;1,700&family=Work+Sans:ital,wght@0,400;0,700;1,700&display=swap");
.bg-container {
background-image: url("https://d1tgh8fmlzexmh.cloudfront.net/ccbp-dynamic-webapps/numbers-fact-bg.png");
background-size: cover;
height: 100vh;
}
.heading {
color: #ffffff;
font-size: 28px;
font-weight: bold;
}
.user-input {
width: 320px;
}
.spinner {
color: #ffffff;
}
.fact-text {
color: #ffffff;
font-size: 18px;
font-weight: bold;
}
NOTE: LINK YOUR CSS & JS File into HTML if you are using VS studio code or any other code playground.
Tags:
JavaScript Practice