Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialThomas Katalenas
11,033 PointsDo property values have to be the same? here's my code.
var objects = [
{ one: "how many wheels on a bycicle",
two: 2
},
{one: "how many tires on a car",
two: 4
},
{one: "how many legs do inesects have",
two: 6
}];
var correctAnswers = 0;
function print(message) {
document.write(message);
}
for( i = 0; i< objects.length; i += 1) {
prit = objects[i].one;
prit1 = objects[i].two;
response = prompt(prit);
response = parseInt(response);
if (response === prit1) {
correctAnswers += 1
}
}
html = "You got " + correctAnswers + " right!!"
print(html)
at first I tried to create a for loop from the previous exercise
for( i = 0; i< objects.length; i += 1) {
for(prop in objects) {
var map = prop;
var prit = objects[i].map;
document.write(prit);
}
}
what's funny about this thing is that if I do document.write(map) the property values propegate, but it does not work for document.write(prit)
the goal is to loop through all values of different name.s
-Radix
1 Answer
Osama Awan
Courses Plus Student 8,676 PointsYou are using prit instead of print, it should have to be: response = prompt(print);
Idan Melamed
16,285 PointsIdan Melamed
16,285 PointsI think the correct syntax should be objects[i][map];