Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Owl practice tasks #61

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions fetch_products/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
*{
margin: 0;
box-sizing: border-box;
}

body{
font-family: Arial, Helvetica, sans-serif;
font-weight: 300;
}

.btn{
background-color: darkcyan;
color: white;
outline: none;
border: none;
cursor: pointer;
width: 120px;
height: 40px;
border-radius: 7px;
text-align: center;
margin: 30px;
font-size: medium;

}

.btn-container{
display: flex;
flex-direction: row;
justify-content: center;
}

#container{
display: grid;
grid-template-columns: repeat(3,630px);
padding: 50px;
}
img{
width: 50%;
margin-bottom: 30px;
}
.card{
width: 450px;
height: 600px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
margin-top: 50px;
padding: 30px;
cursor: pointer;
}

.card:hover{
transform: scale(1.03);
transition: 0.3s ease-in-out;
}
24 changes: 24 additions & 0 deletions fetch_products/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!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">
<link rel="stylesheet" href="index.css">
<title></title>
</head>
<body>
<div class="btn-container">
<button id="btn1" class="btn">
Previous
</button>
<button id="btn2" class="btn">
Next
</button>
</div>
<div class="container" id="container">

</div>
</body>
<script src="index.js"></script>
</html>
54 changes: 54 additions & 0 deletions fetch_products/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
let firstTen
let secondTen
const list = document.getElementById("container")

async function fetchProducts(){
const res = await fetch("https://fakestoreapi.com/products")
const data = await res.json()
return data
}

fetchProducts().then((data) => {
firstTen = data.slice(0,10)
secondTen = data.slice(10,20)
})

function showFirstTen(items){

items.forEach(ele => {
const div = document.createElement("div")
div.classList.add("card")
list.appendChild(div)

const img = document.createElement("img")
img.src = ele.image
div.appendChild(img)

const h1 = document.createElement("h2")
h1.style.fontWeight = "300"
h1.innerHTML = ele.title
div.appendChild(h1)

const p = document.createElement("p")
p.innerHTML = ele.description
p.style.margin = "30px 0"
div.appendChild(p)

const h3 = document.createElement("h3")
h3.style.fontWeight = "300"
h3.innerHTML = `Price: &#36;${ele.price}`
div.appendChild(h3)
})
}

const btn1 = document.getElementById("btn1")
const btn2 = document.getElementById("btn2")
btn1.onclick = () => {
list.innerHTML = ""
showFirstTen(firstTen)
}

btn2.onclick = () => {
list.innerHTML = ""
showFirstTen(secondTen)
}
50 changes: 50 additions & 0 deletions guess_the_number/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
*{
margin: 0;
box-sizing: border-box;
}
body{
font-family: Arial, Helvetica, sans-serif;
}
.container{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}

#input{
width: 250px;
height: 40px;
}

.btn-container{
width: 250px;
display: flex;
justify-content: center;
margin: 30px;
}

#btn{
background-color: darkcyan;
color: white;
outline: none;
border: none;
cursor: pointer;
width: 70px;
height: 40px;
border-radius: 7px;
}

h1{
margin: 30px;
}

.box{
text-align: center;
height: 50vh;
width: 50vw;
display: flex;
flex-direction: column;
align-items: center;
}
26 changes: 26 additions & 0 deletions guess_the_number/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!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">
<link rel="stylesheet" href="index.css">
<script src="index.js" async></script>
<title>Number Guess</title>
</head>

<body>
<div class="container">
<div class="box">
<h1>Enter any number</h1>
<input id="input" placeholder="Enter any number" />
<div class="btn-container">
<button id="btn">Start</button>
</div>
<h1 id="number"></h1>
</div>
</div>
</body>

</html>
37 changes: 37 additions & 0 deletions guess_the_number/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let randomNumber, counter = 0
let h1 = document.getElementById("number")
let inputField = document.getElementById("input")

const btn = document.getElementById("btn")

function guessNumber() {
h1.innerHTML = ""
randomNumber = Math.floor(Math.random() * 10)
}

function checkNumber() {

let inputValue = inputField.value
h1.innerHTML = inputValue
if(inputValue){
counter++
if(randomNumber < inputValue) {
h1.innerHTML = "Guessed number is greater"
}
else if(randomNumber > inputValue){
h1.innerHTML = "Guessed number is smaller"
}
else{
h1.innerHTML = `Number matched! </br>Number of trials: ${counter}`
btn.innerHTML = "Restart"
counter = 0
}

}

}



btn.addEventListener("click",guessNumber)
inputField.addEventListener("input",checkNumber)
50 changes: 50 additions & 0 deletions owl_practice/guess_the_number/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
*{
margin: 0;
box-sizing: border-box;
}
body{
font-family: Arial, Helvetica, sans-serif;
}
.container{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}

#input{
width: 250px;
height: 40px;
}

.btn-container{
width: 250px;
display: flex;
justify-content: center;
margin: 30px;
}

#btn{
background-color: darkcyan;
color: white;
outline: none;
border: none;
cursor: pointer;
width: 70px;
height: 40px;
border-radius: 7px;
}

h1{
margin: 30px;
}

.box{
text-align: center;
height: 50vh;
width: 50vw;
display: flex;
flex-direction: column;
align-items: center;
}
15 changes: 15 additions & 0 deletions owl_practice/guess_the_number/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!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">
<script src="../owl.js"></script>
<link rel="stylesheet" href="index.css">
<title>Guess the number</title>
</head>
<body>

</body>
<script src="index.js"></script>
</html>
Loading