Declarative-Languages / Declarative Language Practical 1 / Question 3 / WeatherWebsite / weather.html
weather.html
Raw
<!DOCTYPE html>
<!--
    File:           weather.html
    Course:         INFO-3138
    Date:           June 16, 2023
    Description:    A website to display the weather data stored in weather.json
-->
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Weather</title>
</head>
<body>
    <script>
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
                var weatherData = JSON.parse(this.responseText);

                document.writeln("<h1>Weather Forcast for " + weatherData.Location + "</h1>");

                for (var d = 0; d < weatherData.Days.length; d++) {

                    document.writeln("<h2>" + weatherData.Days[d].Description + "</h2>");
                    document.writeln("<ul><li>" + weatherData.Days[d].SkyCondition + "</li>");
                    document.writeln("<li>Expected high is " + weatherData.Days[d].High + "</li>");
                    document.writeln("<li>Expected low is " + weatherData.Days[d].Low + "</li></ul>");
                }
            }
        }
        xmlhttp.open("GET", "weather.json", true);
        xmlhttp.send();
    </script>
</body>
</html>