Unable to get data from object

designerNProgrammer

newbie here. i have made an object like this

var myMovie1=
        {

            title:'Plan 9 from Outer Space',
            genre:'Classic',
            rating:3,
            showTimes:[6,8,11]

        };


        var myMovie2=
        {

            title:'Rush',
            genre:'Action',
            rating:5,
            showTimes:[3,6,14]

        };

Now created functions to check current time and movie alerts like this

// function to get date and time
var now =new Date().getHours();


function letsSeeMovie(myMovieSelected){
    for (var i = 0; i < myMovieSelected.showTimes.length; i++) {
        var showTime=myMovieSelected.showTimes[i];

        if (now<showTime) {
            return "The next moive starts at " + showTime + "am";
        }
        else
        {
            return "sorry you just missed it"
        }

    }
}
var okcanWeSeeit=letsSeeMovie(myMovie2);
document.write(okcanWeSeeit);

But somehow in the moive object it only displays "sorry missed it". it dosent **reach 11* and show the next playing time. Where i am doing it wrong?? Thanks.

Tim

You should return after iterating all the myMovieSelected

function letsSeeMovie(myMovieSelected){
    for (var i = 0; i < myMovieSelected.showTimes.length; i++) {
        var showTime=myMovieSelected.showTimes[i];
        console.log(showTime)
        if (now<showTime) {
            return "The next moive starts at " + showTime + "am";
        }

    }

    return "u miss it"
}

What you did just now is, you iterate the first element, if it doesnt match you already break the loop

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Unable to get data from Intent in Activity

분류에서Dev

Unable to get currentUser PFUser object from Parse.com

분류에서Dev

Unable to get bundle data from two different activities

분류에서Dev

Unable to get input data sent from cross site domain

분류에서Dev

Unable to get images from a link

분류에서Dev

Unable to get $rootscope object on pageload in angularjs

분류에서Dev

unable to retrieve field values from object laravel

분류에서Dev

Swift - Unable to create JSON object from NSData

분류에서Dev

To get view object from UITableviewCell

분류에서Dev

Pull data from a PHP object

분류에서Dev

Unable to get maximum resolution from external display

분류에서Dev

Unable to populate data in listView from Database in Android

분류에서Dev

Unable to get the Object property of the OLEObject class - Excel Interop

분류에서Dev

To get data from another activity

분류에서Dev

Emberjs : get data from input

분류에서Dev

How to get data from response

분류에서Dev

Unable to create System.Drawing.Image object from WebResponse Stream

분류에서Dev

Kendo Unable to get property 'data'of undefined or null reference

분류에서Dev

How to get object from array in swift

분류에서Dev

Is it possible to get the DataSourceRequest from KendoUI DataSource object?

분류에서Dev

How do datatypes get their properties from Object?

분류에서Dev

Get object from array with NSDictionary objects

분류에서Dev

Android: How to get bitmap from HashMap object?

분류에서Dev

Get WebView object from Fragment to Activity

분류에서Dev

How to get values from Deserialized JSON object?

분류에서Dev

Hibernate - get Object version from db

분류에서Dev

JQuery : Get a value from the result object array

분류에서Dev

javascript get inner object from function

분류에서Dev

How to get object coordinates from screen coordinates?

Related 관련 기사

  1. 1

    Unable to get data from Intent in Activity

  2. 2

    Unable to get currentUser PFUser object from Parse.com

  3. 3

    Unable to get bundle data from two different activities

  4. 4

    Unable to get input data sent from cross site domain

  5. 5

    Unable to get images from a link

  6. 6

    Unable to get $rootscope object on pageload in angularjs

  7. 7

    unable to retrieve field values from object laravel

  8. 8

    Swift - Unable to create JSON object from NSData

  9. 9

    To get view object from UITableviewCell

  10. 10

    Pull data from a PHP object

  11. 11

    Unable to get maximum resolution from external display

  12. 12

    Unable to populate data in listView from Database in Android

  13. 13

    Unable to get the Object property of the OLEObject class - Excel Interop

  14. 14

    To get data from another activity

  15. 15

    Emberjs : get data from input

  16. 16

    How to get data from response

  17. 17

    Unable to create System.Drawing.Image object from WebResponse Stream

  18. 18

    Kendo Unable to get property 'data'of undefined or null reference

  19. 19

    How to get object from array in swift

  20. 20

    Is it possible to get the DataSourceRequest from KendoUI DataSource object?

  21. 21

    How do datatypes get their properties from Object?

  22. 22

    Get object from array with NSDictionary objects

  23. 23

    Android: How to get bitmap from HashMap object?

  24. 24

    Get WebView object from Fragment to Activity

  25. 25

    How to get values from Deserialized JSON object?

  26. 26

    Hibernate - get Object version from db

  27. 27

    JQuery : Get a value from the result object array

  28. 28

    javascript get inner object from function

  29. 29

    How to get object coordinates from screen coordinates?

뜨겁다태그

보관