Skip to content

Ballin Oates Weather API #8

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<head>
<title>Ballin'Oates Weather</title>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script defer src="script.js"></script>
</head>

<body>
<h1>Ballin' Oates Knowz Weather...API</h1>
<br>
<h2>I can't go for that... Umbrella</h2>
<br>
<h3 id = 'umbrella'></h3>
<br>
<form style="display: flex;">
<p class="body-text">Will I need an umbrella in</p>
<input type="text" value="" placeholder="Enter location" id="inputBar">
<input type="button" value="Find Out" id="searchButton">
</form>
<div style = "display: flex;">
<h3 id="umbrellaAnswer"></h3>
<h2 id="cityName"></h2>
<br>

</div>
<h3 id="looksLike"></h3>
<h3></h3>
<div style="display: flex;">
<div id="currentImg"></div>
<h2 id="currentFore"></h2>
</div>

<h2 id="sevenDay"></h2>
<div style="display: flex;">
<div class="foreimg"></div>
<div class="foreimg"></div>
<div class="foreimg"></div>
<div class="foreimg"></div>
<div class="foreimg"></div>
<div class="foreimg"></div>
<div class="foreimg"></div>
</div>

<div style="display: flex; padding-left: 16px ;">
<h2 style="display: flex;">
<div class="foreday" style = "padding-right: 32px ;"></div>
<div class="foreday" style = "padding-right: 32px ;"></div>
<div class="foreday" style = "padding-right: 32px ;"></div>
<div class="foreday" style = "padding-right: 32px ;"></div>
<div class="foreday" style = "padding-right: 32px ;"></div>
<div class="foreday" style = "padding-right: 32px ;"></div>
<div class="foreday" style = "padding-right: 32px ;"></div>
</h2>
</div>

</header>
<div></div>
</body>
58 changes: 58 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const apiKey = 'cf208495165446d390c161013230804'

let button = document.querySelector("#searchButton")
let forImgArray = document.querySelectorAll('.foreimg')
let forDayArray = document.querySelectorAll('.foreday')
const d = new Date();
let day = d.getDay()

console.log(forImgArray)

button.addEventListener('click', async () => {

let textInput = document.querySelector("#inputBar").value
let cityName = document.querySelector("#cityName")
let todImage = document.querySelector("#todImage")
const imageDiv = document.querySelector("#currentImg")
const umbrellaAnswer = document.querySelector("#umbrellaAnswer")
const currentFore = document.querySelector("#currentFore")
const looksLike = document.querySelector("#looksLike")
const sevenDay = document.querySelector("#sevenDay")

let response = await axios.get(`http://api.weatherapi.com/v1/forecast.json?key=cf208495165446d390c161013230804&q=${textInput}&days=7&aqi=no&alerts=no`)
let citName = response.data.location.name
let todImg = response.data.current.condition.icon

// let umbAnswer
let grabUmbrellaCode = response.data.current.condition.code
let curFore = response.data.current.condition.text

console.log(response)

if (grabUmbrellaCode > 1029){
umbrellaAnswer.innerText = "You should probably grab an umbrella if you are currently in"
} else {
umbrellaAnswer.innerText = "Ballin Oates says that you shouldn't need an umbrella if you in"
}



looksLike.innerText = "The forecast looks like:"
//console.log(forecastArray)
cityName.innerText = citName
imageDiv.innerHTML = `<img src=${todImg}>`
currentFore.innerText = curFore
sevenDay.innerText = 'The 7 day Forecast:'

for (let i = 0; i < 7; i++){
let forecastArray = response.data.forecast.forecastday[i].day.condition.icon
forImgArray[i].innerHTML = `<img src=${forecastArray}>`
}

for (let i = 0; i < 7; i++){
const dayArray = ['sun', 'mon', 'tues', 'wed', 'thurs', 'fri', 'sat', 'sun', 'mon', 'tues', 'wed', 'thurs', 'fri', 'sat', 'sun']
forDayArray[i].innerText = dayArray[day]
day ++
}

})
Empty file added style.css
Empty file.