I need to show the high and low temperature for the current day using mathrandom and then include the temperature for the rest of the week. However when I put in my function for the temperature for the remaining week, I just get a list of Thursdays... I'm not sure what I'm doing wrong.
// display the forecast
var elem = document.getElementById("moncForecast");
`enter code here`displayForecast(elem);
/*
Create a new Date object for each of the 5 forecasts, then extract the day of the
week and display it. You can change the number of forecasts to whatever suits your needs.
*/
function displayForecast(divElem, currentDate)
{
for (var i = 1; i <= 1; i++)
{
var currentDate= new Date ();
var elem = document.getElementById ("displayDate")
var forecast = getDateForForecast(currentDate, i);
dayOfWeek = forecast.getDay();
divElem.innerHTML = currentDate + " Low: " + getLowTemp() + " High: " + getHighTemp() + "<br>";
for (var i=1; i <=5; i++) {
divElem.innerHTML += weekdays[dayOfWeek] + " Low: " + getLowTemp () + "High" + getHighTemp () + "<br>";
}
}
}
/*
Return a low temperature using the Math.random method.
*/
function getLowTemp()
{
return Math.floor(Math.random() * 5) + 10;
}
/*
Return a high temperature using the Math.random method.
*/
function getHighTemp()
{
return Math.floor(Math.random() * 10) + 15 ;
}
here is the original code, hopefully you'll be able to show me where I have gone wrong because I cannot figure it out.
// display Winnipeg date and time
var wpgTime = getDateByOffset(-5);
var elem = document.getElementById("wpgTime");
elem.innerHTML = wpgTime;
// display the forecast
var elem = document.getElementById("wpgForecast");
displayForecast(elem, wpgTime);
// display Toronto date and time
var torTime = getDateByOffset(-4);
elem = document.getElementById("torTime");
elem.innerHTML = torTime;
// display the forecast
elem = document.getElementById("torForecast");
displayForecast(elem, torTime);
/*
Create a new Date object for each of the 5 forecasts, then extract the day of the
week and display it. You can change the number of forecasts to whatever suits your needs.
*/
function displayForecast(divElem, currentDate)
{
for (var i = 1; i <= 3; i++)
{
var forecast = getDateForForecast(currentDate, i);
dayOfWeek = forecast.getDay();
divElem.innerHTML += weekdays[dayOfWeek] + ":" + getLowTemp() + getHighTemp() + "<br>";
}
}
/*
Return a low temperature using the Math.random method.
*/
function getLowTemp()
{
return "<span style='margin-left:15px'>Low 0°C </span>";
}
/*
Return a high temperature using the Math.random method.
*/
function getHighTemp()
{
return "<span style='margin-left:25px'>High 0°C </span>";
}
The html code is below.
<html lang = "en">
<head>
<title>What's the weather?</title>
<meta charset = "UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
</head>
<body>
<div class="main-image">
<div class="header">
<h1> What's the Weather? | </h1>
</div>
<div id="showDate"> </div>
<div id ="nav">
<a href="index.html">Home</a>
<a href="news.html">News</a>
<div class="dropdown">
<button class="dropbtn">Weather
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="winnipeg.html">Winnipeg</a>
<a href="victoria.html">Victoria</a>
<a href="moncton.html">Moncton</a>
</div>
</div>
</div>
<body style="font-family:Arial">
<div class="weather">
<h3>Winnipeg Weather</h3>
<!-- Vancouver -->
<p>Time</p>
<div id="moncTime"></div>
<p style="font-weight:bold">Winnipeg forecast:</p>
<div id="moncForecast"></div>
</div>
<script src="example11-09a.js"></script>
<script src="moncton.js"></script>
</body>
</html>