i am unable to find the solution for this code these are the questions

Multi tool use
Multi tool use


i am unable to find the solution for this code these are the questions



● Write a function to take pokemon’s name as argument and display the
information of that pokemon
● Write a function that takes pokemon’s name as an argument and find out
which all pokemon have that name in their “next_evolution” field.
● Write a function that take a “Weakness” as an input and gives the names
of all pokemon who have that Weakness. (check the weakness array in
the dataset).



it doesnt show any error nor not finding the solution ... i need help in solving this,i am a beginner so the detailed logic or code would be helpful




var goPokemon = {
"pokemon": [{
"id": 1,
"num": "001",
"name": "Bulbasaur",
"img": "http://www.serebii.net/pokemongo/pokemon/001.png",
"type": [
"Grass",
"Poison"
],
"height": "0.71 m",
"weight": "6.9 kg",
"candy": "Bulbasaur Candy",
"candy_count": 25,
"egg": "2 km",
"spawn_chance": 0.69,
"avg_spawns": 69,
"spawn_time": "20:00",
"multipliers": [1.58],
"weaknesses": [
"Fire",
"Ice",
"Flying",
"Psychic"
],
"next_evolution": [{
"num": "002",
"name": "Ivysaur"
}, {
"num": "003",
"name": "Venusaur"
}]
}, {
"id": 2,
"num": "002",
"name": "Ivysaur",
"img": "http://www.serebii.net/pokemongo/pokemon/002.png",
"type": [
"Grass",
"Poison"
],
"height": "0.99 m",
"weight": "13.0 kg",
"candy": "Bulbasaur Candy",
"candy_count": 100,
"egg": "Not in Eggs",
"spawn_chance": 0.042,
"avg_spawns": 4.2,
"spawn_time": "07:00",
"multipliers": [
1.2,
1.6
],
"weaknesses": [
"Fire",
"Ice",
"Flying",
"Psychic"
],
"prev_evolution": [{
"num": "001",
"name": "Bulbasaur"
}],
"next_evolution": [{
"num": "003",
"name": "Venusaur"
}]
}, {
"id": 3,
"num": "003",
"name": "Venusaur",
"img": "http://www.serebii.net/pokemongo/pokemon/003.png",
"type": [
"Grass",
"Poison"
],
"height": "2.01 m",
"weight": "100.0 kg",
"candy": "Bulbasaur Candy",
"egg": "Not in Eggs",
"spawn_chance": 0.017,
"avg_spawns": 1.7,
"spawn_time": "11:30",
"multipliers": null,
"weaknesses": [
"Fire",
"Ice",
"Flying",
"Psychic"
],
"prev_evolution": [{
"num": "001",
"name": "Bulbasaur"
}, {
"num": "002",
"name": "Ivysaur"
}]
}]
}






var DetailOfPokemon = function(name, goPokemon) {

for (var x in goPokemon.pokemon)
{
if (goPokemon.pokemon[x].name == findname)
{
var Detail = goPokemon.pokemon[x];
alert(Detail);
} else {
}
}

var findname = window.prompt('Enter the name of Pokemon')

};
DetailOfPokemon(name,goPokemon)





@VicJordan Asking about homeworks is on-topic at SO, as long as something has been tried, and the problem is described. That seems to be the case in this post.
– Teemu
Jul 3 at 7:52






The title of the question is not a question.
– Jorgeblom
Jul 3 at 8:11




1 Answer
1



var findname = window.prompt('Enter the name of Pokemon') is badly placed. You compare goPokemon.pokemon[x].name with findname and findname isn't yet defined.


var findname = window.prompt('Enter the name of Pokemon')


goPokemon.pokemon[x].name


findname


findname



The function JSON.stringify() will convert an object into a json string (might be easier to display the informations).



By the way, if you don't need an else instruction, don't write it.


else




var goPokemon = {
"pokemon": [{
"id": 1,
"num": "001",
"name": "Bulbasaur",
"img": "http://www.serebii.net/pokemongo/pokemon/001.png",
"type": [
"Grass",
"Poison"
],
"height": "0.71 m",
"weight": "6.9 kg",
"candy": "Bulbasaur Candy",
"candy_count": 25,
"egg": "2 km",
"spawn_chance": 0.69,
"avg_spawns": 69,
"spawn_time": "20:00",
"multipliers": [1.58],
"weaknesses": [
"Fire",
"Ice",
"Flying",
"Psychic"
],
"next_evolution": [{
"num": "002",
"name": "Ivysaur"
}, {
"num": "003",
"name": "Venusaur"
}]
}, {
"id": 2,
"num": "002",
"name": "Ivysaur",
"img": "http://www.serebii.net/pokemongo/pokemon/002.png",
"type": [
"Grass",
"Poison"
],
"height": "0.99 m",
"weight": "13.0 kg",
"candy": "Bulbasaur Candy",
"candy_count": 100,
"egg": "Not in Eggs",
"spawn_chance": 0.042,
"avg_spawns": 4.2,
"spawn_time": "07:00",
"multipliers": [
1.2,
1.6
],
"weaknesses": [
"Fire",
"Ice",
"Flying",
"Psychic"
],
"prev_evolution": [{
"num": "001",
"name": "Bulbasaur"
}],
"next_evolution": [{
"num": "003",
"name": "Venusaur"
}]
}, {
"id": 3,
"num": "003",
"name": "Venusaur",
"img": "http://www.serebii.net/pokemongo/pokemon/003.png",
"type": [
"Grass",
"Poison"
],
"height": "2.01 m",
"weight": "100.0 kg",
"candy": "Bulbasaur Candy",
"egg": "Not in Eggs",
"spawn_chance": 0.017,
"avg_spawns": 1.7,
"spawn_time": "11:30",
"multipliers": null,
"weaknesses": [
"Fire",
"Ice",
"Flying",
"Psychic"
],
"prev_evolution": [{
"num": "001",
"name": "Bulbasaur"
}, {
"num": "002",
"name": "Ivysaur"
}]
}]
}






var DetailOfPokemon = function(findname, goPokemon) {
for (var x in goPokemon.pokemon)
{
if (goPokemon.pokemon[x].name == findname)
{
var Detail = goPokemon.pokemon[x];
alert(JSON.stringify(Detail, null, 4));
}
}
};
var name = window.prompt('Enter the name of Pokemon')
DetailOfPokemon(name, goPokemon)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

lDK JMi5eoSe584C,9dI
L1vLutAKvO4wvqo,3SugVcNfaqH589yLryfUF CoNu,GKr,Xwoug6z sOV

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications