Definitions have not been declared

My coding is as follows:


var data = JSON.parse(http.responseText);
    var weatherData = new Weather(cityName, data);
    weatherData.temperature = data.main.temp;
    updateWeather(weatherData);

function Weather(cityName, data) {
this.cityName = cityName
data.weather[0].description = descriptions;
this._temperature = '';
}

function updateWeather(weatherData) {
weatherCity.textContent = weatherData.cityName;
weatherDescription.textContent = weatherData.descriptions;
weatherTemperature.textContent = weatherData.temperature;

loadingText.style.display = 'none';
weather.style.display = 'block';

I encountered an error stating that "descriptions is not defined". The code works fine if I make the following adjustment:


var data = JSON.parse(http.responseText);
    var weatherData = new Weather(cityName, data.weather[0].description);
    weatherData.temperature = data.main.temp;
    updateWeather(weatherData);

function Weather(cityName, description) {
this.cityName = cityName
this.description = descriptions;
this._temperature = '';
}

function updateWeather(weatherData) {
weatherCity.textContent = weatherData.cityName;
weatherDescription.textContent = weatherData.descriptions;
weatherTemperature.textContent = weatherData.temperature;

loadingText.style.display = 'none';
weather.style.display = 'block';

I am unsure about what to do now. Could it be that I am not receiving a value back? If someone could provide a fix so that I can understand better, that would be greatly appreciated. I am fairly new to this, so please excuse any naive questions. I was attempting the first method because I have additional information like weather pressure, wind speed, sunrise, etc., that I want to incorporate.

Answer №1

There is a mistake in the code snippet below -

function Weather(cityName, description) {
this.cityName = cityName
this.description = descriptions;
this._temperature = '';

Kindly rectify this.description = descriptions to this.description = description

Answer №2

present

function Climate(cityName, weather) {
    this.cityName = cityName
    this.weather = climaticCondition;  
    this._temperature = '';
}

you mistakenly used climaticConditions instead of weather

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a C# Web API that Only Returns Values, Not Keys

I am currently developing a Web API using C#, and my goal is to only retrieve the values without the keys. I am fetching data from a DataSet and here is an example of what I have so far; { "Role": [ { "PersonName" ...

Discover the Power of Node.js with the @aws-sdk/client-s3 Package, Leveraging AWS CLI Credentials Stored in

A Nodejs project has been set up with media files stored in an S3 Bucket and utilizing the @aws-sdk/client-s3 as the AWS SDK Client. The project consists of two important files, namely .env and S3Bucket.js. The content of .env (located in the root directo ...

AngularJS: splitting the parent <div> into multiple sections every nth element

I have an array of strings in Javascript and I am attempting to use AngularJS to create nested <div> elements. var arr = ["abc", "def", "ghi", "jkl", "mno", "pqr", "stu"]; My goal is to group every 3 elements together like so. <div class="pare ...

Choose an image and save the selection information for the following page (Tarot card)

I'm in the process of creating a website that showcases multiple tarot cards. The goal is for users to select the cards they're interested in and have their chosen card displayed on the next page. I've implemented some code for selecting the ...

Creating a character jump animation on an HTML5 canvas

While following a tutorial on creating character animations, I encountered an issue. The tutorial, located at , made it easy to make the character move left (the right movement was already implemented). However, I am struggling with how to animate the char ...

VueJS TypeScript with ChartJS - Unexpected Token '}' Parsing Error

I have integrated Chart.js into my Vue project. After installing chart.js and @types/chart.js using npm, I included a chart.d.ts file with the line declare module 'chart.js'; . Encountered an error which can be viewed https://i.sstatic.net/8npR ...

Leveraging JavaScript to access the margin-top property of the HTML and body tags

I'm having trouble retrieving the "marginTop" style property from the <html> and <body> tags. While Chrome developer tools shows that margin-top is being set via in-HTML CSS: <style type="text/css" media="screen"> html { margin-top: ...

Why is "undefined" being used to alert an ajax call response?

I am encountering an issue with a returned value from an AJAX request. The web method being referenced returns a boolean value of true or false. However, when attempting to access this value outside the AJAX method, I am receiving an "undefined" message :? ...

Performing a AJAX POST call to the latest Google Analytics V4 API

Recently, the Google Analytics v4 API was updated and now requires POST requests instead of GET requests. Unfortunately, there are not many examples available yet... I managed to obtain the accessToken, but when I attempt the following POST request, I alw ...

numerous sections within a solitary webpage

I need to implement multiple tabs on a single page, how do I modify the code to make this possible? Take a look at the codepen for reference. Here is the jquery code I have written so far: var tabs = $(".tabContainer ul li a"); $(".tabConten ...

"Otherwise, refrain from modifying and simply view the image with jQuery for uploading the size

I am having an issue with image size validation. Whenever I try to upload an image, I receive a warning message if the file size is larger than 1 MB. However, if I upload an image with a file size less than 1 MB, the message does not disappear. Below is ...

Transform JSON into a format that is compatible with Prometheus for easy reading

I'm currently facing an issue with converting my API response from JSON format to Prometheus format. I've tried using jq and other methods but haven't been successful in capturing the metrics on the Prometheus UI. { "version": &q ...

After clicking on the checkbox, req.body.task becomes undefined

Whenever I click on the checkbox, the value of req.body.task returns as undefined. <input type="checkbox" name="task" autocomplete="off" checked="" onchange="onToDochange({{id}})"> This function is triggered by a change event on the checkbox and it ...

Order of tabs, dialog, and forms customization using Jquery UI

I'm currently working on a jquery dialog that contains a form split into multiple tabs. In order to enhance keyboard navigation, I am looking for a way to make the tab key move from the last element of one tab to the first element of the next tab. Cur ...

Transforming Lapton images into JPEG format on the fly

I have been working on a project where I am compressing jpeg images to .lep format. Now, I have created an .exe file that can convert the .lep image back to jpeg. My goal is to write a simple JSP script that can decode the .lep image on-the-fly and displ ...

What is the best way to integrate ngx-translate's pipe for global translation?

I'm currently utilizing the ngx-translate package in order to internationalize my Angular application. When translating text using the translate pipe like so: {{ 'title' | translate }} An issue arises when attempting to use this pipe in ot ...

Is the iCheck feature designed to block all parent click events?

I've developed an "interaction tracker" system that collects anonymous data on clicked page elements. By implementing an event listener for clicks on the body, I can track interactions with any element on my site successfully. However, interestingly ...

Place 4 divs within 2 divs, with one aligned to the left and the other to the right

I'm currently working on a small project using Angular 2 for an experiment, where I need to place 4 divs, each containing an image, within 2 divs. However, all the divs (with images) are stacked vertically instead of being placed next to each other, ...

Experiencing a result of NaN following a mathematical operation on variables

While working with an array obtained from a JSON response, I am encountering NaN after performing addition operations. var a = new Array(); var b = 0; var c = 0; alert(b); for (var x = 0; x < length; x++) { a[x] = response.data[x] } for (var i = 0; ...

Concealing information based on the value of a variable

Creating a dynamic price estimator. I need help writing a jQuery function that can hide or show a specific div element based on the value of a variable. For example, let's say I have an HTML div with the ID 'Answer': <div id="answer"&g ...