Skip to content

Commit 0374bcf

Browse files
committed
first commit
0 parents  commit 0374bcf

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

app.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const input=document.querySelector(".input");
2+
const p=document.querySelector("#info");
3+
const meaningCont=document.querySelector(".meaning-container");
4+
const title=document.querySelector(".title");
5+
const meaning=document.querySelector(".meaning");
6+
const audio=document.querySelector("#audio");
7+
8+
async function fetchApi(word){
9+
try {
10+
// console.log(word);
11+
p.style.display="block";
12+
meaningCont.style.display="none";
13+
p.innerText=`Searching the meaning of ${word}...`;
14+
15+
16+
const url=` https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;
17+
console.log(url);
18+
const result=await fetch(url).then((res)=>
19+
res.json());
20+
21+
if(result.title){
22+
p.style.display="block";
23+
meaningCont.style.display="none";
24+
25+
title.innerText=word;
26+
meaning.innerText="N/A";
27+
audio.style.display="none";
28+
}
29+
console.log(result);
30+
p.style.display="none";
31+
meaningCont.style.display="block";
32+
title.innerText=result[0].word;
33+
meaning.innerText=result[0].meanings[0].definitions[0].definition;
34+
audio.src=result[0].phonetics[0].audio;
35+
} catch (error) {
36+
console.log(error);
37+
// p.innerText="An error happened, please try again later";
38+
p.innerText=`${error}`;
39+
}
40+
}
41+
42+
input.addEventListener("keyup",(event)=>{
43+
// console.log(event);
44+
// console.log(event.target);
45+
// console.log(event.key);
46+
// console.log(event.target.value);
47+
if(event.target.value && event.key ==="Enter"){
48+
fetchApi(event.target.value);
49+
}
50+
51+
})

index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>English Dictionary</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<div class="main">
11+
<div class="container">
12+
<h1>English Dictionary</h1>
13+
<input type="text" class="input" placeholder="Search a word" >
14+
<p id="info">Type a word and press enter</p>
15+
16+
<div class="meaning-container">
17+
<p>Word Title : <span class="title">___</span> </p>
18+
<p>Meaning : <span class="meaning">___</span></p>
19+
<audio src="" controls id="audio"></audio>
20+
</div>
21+
</div>
22+
</div>
23+
<script src="app.js"></script>
24+
</body>
25+
</html>

style.css

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.main{
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
height: 100vh;
6+
background-color: salmon;
7+
margin: 0;
8+
padding: 0;
9+
font-family: 'Courier New', Courier, monospace;
10+
}
11+
.container{
12+
/* display: flex;
13+
flex-direction: column;
14+
justify-content: center;
15+
align-items: center; */
16+
text-align: center;
17+
background-color: rgba(255,255,255,0.3);
18+
margin: 20px;
19+
padding: 28px;
20+
width: 85%;
21+
max-width: 400px;
22+
box-shadow: 0px 10px 10px rgba(0,0,0,0.3 );
23+
border-radius: 7px;
24+
font-weight: 500;
25+
font-size: 18px;
26+
}
27+
.input{
28+
width: 80%;
29+
/* height: 3px; */
30+
/* text-align: center; */
31+
padding: 15px 30px;
32+
border: 2px solid black;
33+
border-radius: 5px;
34+
background-color: rgb(255,255,255,0.6);
35+
font-size: 16px;
36+
}
37+
#audio{
38+
border-radius: 50px;
39+
background-color: white;
40+
}
41+
42+
.meaning-container{
43+
display: none;
44+
}

0 commit comments

Comments
 (0)