Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i was supposed to be able to get the info of episode and season given by the user from following dataset


https://s3-ap-southeast-1.amazonaws.com/edwisor-india-bucket/assignments/we
b03/JSS1l2/bigbangtheory.json

What I have tried:

let obtain=(season,episode)=>

{
  var seasonfound=false
  var episodefound=false
  for (var i of information.embedded.episode)
  {
    if(information.embedded.episode[i].season==season)
    {
      if(information.embedded.episode[i].number==episode)
      {
        seasonfound=true
        episodefound=true
         break
      }
      else{
        seasonfound=true
        episodefound=false
        break
      }
    }
    else
    {
      seasonfound=false
    }
  }
  if (seasonfound==true && episodefound==true)
  {

    alert(info[i].id)
  }
  else{
    alert('incorrect')
  }

   

     }

 

let S=window.prompt('enter the seaseon you wish')

let E=window.prompt('enter the episode you wish')

obtain(S,E)
Posted
Updated 12-Jul-18 6:45am

1 solution

If the problem is that you obtain 'INCORRECT' if in the dataset exists a record that belongs to the same season but it is not of the same episode BEFORE a record with the two matches, in my opinion you can change the code for:

JavaScript
let obtain=(season,episode)=>
{
  var found=false
  for (var i of information.embedded.episode)
  {
    if (  (information.embedded.episode[i].season==season) && (information.embedded.episode[i].number==episode) )
    {
      found=true;
    }
  }
  if (found==true)
  {
    alert(info[i].id)
  }
  else{
    alert('incorrect')
  }

   

     }

 

let S=window.prompt('enter the seaseon you wish')

let E=window.prompt('enter the episode you wish')

obtain(S,E)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900