Why am I getting undefined error? [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
the syntax seems to be correct, I dont get it, here is
error: app.js:73 Uncaught ReferenceError: getBirthyear is not defined
Code:
const person = {
name: 'Tommy',
age: 32,
location: {
state: 'Missouri',
city: 'louisisana',
street: '1 marcia drive',
job: 'web dev'
},
getBirthyear: function() {
return 2018 - this.age;
}
}
let val;
val = getBirthyear();
document.write(val);

You can call it by using person.getBirthday() since it is a property of person

Related

How to add extra property in object [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 26 days ago.
Improve this question
I'm trying to update the object with this field included: [{ name: 'Euler', age: 27, location: 'remote' }]
at the moment the str is: [{ name: 'Euler', age: 27 }] so the location fields needs to be added.
I've done this so far:
function updateRemoteStudents (str) {
str["Location"] = "remote";
console.log (str);
// Your code here
}
result i get is: [{ name: 'Euler', age: 27 }, Location: 'remote' ].
How can i change the function to reflect what i want (sorry new to coding)
[{ name: 'Euler', age: 27, location: 'remote' }]
change to str[0]["Location"] = "remote"; because you are passing an array.

The find function is not available on my array object [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
Consider this simple attempt to find a value in an object:
var config = {
product1: {
ids: ['master']
},
product2: {
ids: ['ps1', 'ps2']
}
};
var id = 'ps2';
var slotID = 'master';
var categorySlotIds = config[slotID].ids;
categorySlotIds.find(id);
I get: TypeError: Cannot find function find in object product1, product2
If I do typeof(categorySlotIDs) the result is object.
The manual for find says: The find() method returns the first element in the provided array
What gives?

Displaying JSON objects [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Trying to displaying individual elements of staff variable in javascript displays undefined in console
<script>
var staff = {"stdinfo" :{"si": "HH01", "sn":"DAVE BAN", "sc":"HGT 1 ", "scid":"44"},"stdinfo1" :{"si": "HH16", "sn":"DEOR ORIE MAR", "sc":"JHT 3", "scid":"31"}};
</script>
console.log(staff.stdinfo0.si) displays undefined. What am I doing wrong?
Your confusing stdinfo with stdinfo0, It's missing the curly brackets, and it has an extra ".
var staff = {
"stdinfo0": {"si": "HH01", "sn":"DAVE BAN", "sc":"HGT 1 ", "scid":"44"},
"stdinfo1": {"si": "HH16", "sn":"DEOR ORIE MAR", "sc":"JHT 3", "scid":"31"}
};

how to assign values to undefined objects? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
var data = {};
data.info.id = "alpha";
This logs to the console: "TypeError: data.info is undefined".
Well that's great and all but I need to store a value in data.info.id. Isn't that what objects are supposed to do?
This should produce an object that looks like this:
data: {
info: {
id: "alpha"
}
}
Is data.info = {} really a necessary step?
In response to Patrick Evans - that's an unrelated question.
Well there is another way. That's putting the info-object directly in the data-object like this:
var data = {
info: {}
}
data.info.id = "alpha";
console.log(data);

Javascript String.replace [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Can someone please explain why this code isn't working?
(it has been simplified for this example)
$(document).ready(function () {
var test = 'broken';
test = test.replace('broken','working');
console.log(test); // working
var field = $('[for="tournament_name"]').html();
console.log(field); // Tournament Name:
console.log(typeof field); // string
field = field.relpace(':',''); // Uncaught TypeError: undefined is not a function
});
I don't understand why it is saying replace() is undefined?
I did read through the docs, what am I missing here?
Maybe it's a typo:
relpace --> replace

Categories

Resources