Need help ASAP coding problem

Need help ASAP coding problem
0.0 0

#1
drunk_ppl = [{name: 'Mark', age: 20,  alcohol_type: 'Whiskey'},
	{name: 'Jon',  age: 25,  alcohol_type: 'Rum'},
	{name: 'April',  age: 22,  alcohol_type: 'Gin'},
	{name: 'Simon',  age: 50,  alcohol_type: 'Vodka'}];

smoker = [{name: 'Mark', cig_a_day: 20, brand: 'Marlboro'},
	 {name: 'Jon', cig_a_day: 15, brand: 'Camel'},
	 {name: 'April', cig_a_day: 12, brand: 'Newport'},
	 {name: 'Simon', cig_a_day: 5, brand: 'Dunhill'}];

var drunkard = []; //creating empty array
for(var i = 0; i < drunk_ppl.length; i++) {
	drunkard[i] = drunk_ppl[i].name; //adding the required fied(here "name") in array
}	

above is sample code snippet.
The requirement is i have to take names from one array (i.e., drunk_ppl) and using second array (i. e., smoker) print the ‘brand’ of each person.

Any suggestion ?
Thanks in advance


#2

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://freecodecamp.org.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

Will the smoker array have the same names as drunk_ppl array? If a name in drunk_ppl does not have a related name/brand in smoker array, what should be displayed?


#5

thanks for the formatting. i’m new here.


#6

basically i want something like this:

for people in drunk_ppl
add person’s name in drunkard

from drunkard array take a name and use that name to find brands of ciggarete from the smoker array
for person’s name in smoker
if name is not in smoker array
print name not found


#7

thanks for the codepen suggestion, in a hurry i pasted in the whole code as it is. will keep in mind next time


#8

In that case, I recommend putting the drunk_ppl arrays names into an object (instead of array), so you do not have to loop through that array. Then just use a for loop similar to the one in your sample code to iterate through the smokers array and check if the object you created of the drunk_ppl’s names has a property for the applicable smoker’s array name.