dcsimg
www.webdeveloper.com
Page 4 of 4 FirstFirst ... 234
Results 46 to 57 of 57

Thread: for() loop and decrements

  1. #46
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    200
    Yeah, takes time to take all this info in, Douglas...lol. Funny thing is, after all this work I do with JavaScript, I'll be migrating to PHP later, and won't be using it. I never have liked the client-side aspect of JavaScript, but I didn't know I could get a PHP runtime environment of my own to do local testing. Live and learn...heh
    Your friendly neighborhood Okham. -o-o-

  2. #47
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    200
    Okay, I've replaced all my items elements...I placed the constructor function in the head, but I found that the for() loop for including the item files doesn't work if I place it in the head. I have to put it in the script following the body. With that setup, it hasn't worked. I think there's something wrong with the syntax of declaring the items[]. I did it the way you indicated, as
    Code:
    items[1]=new items(itemno_1,itemcost_1,itempic_1,ListSelect_1,itemname_1);
    I found, though, that I couldn't access the array. I tried declaring the rows in several different ways after that. The only way I found it worked was
    Code:
    items[1]=[itemno_1,itemcost_1,itempic_1,ListSelect_1,itemname_1];
    So I tried placing the constructor method in the head, and then in the script following the body, and neither one worked. Don't really know where to go with it from here, other than changing back my row declarations in my item files to what they were previously. Do you have any suggestions? I'm disappointed I haven't got the objects to work yet....--okham
    Your friendly neighborhood Okham. -o-o-

  3. #48
    Join Date
    Jan 2017
    Location
    Madison, Wisconsin state
    Posts
    55
    ... lots of information to digest here in this "thread"... I do extend the compliments of my appreciation to Those that have contributed to this throughout. My grey-matter is "MUSH" currently concerning the in-depth concentration of coding presented herein. I'm very grateful to have the capability (and opportunity) to Skim, Read, and Peruse in the hearing (reading) all this Professional Instruction and Guidance. MUSH is what happens to me when I'm immersed deeply into an area that I know will be of good cause for me ...
    Smiling ... I know where I'll be for the next month, or so, easily in my time available for growing in coding - particular to JavaScript.

    Okham - every Programming/Coding Language has its benefit and place in a Web Page. I view: While PHP is great for Server-side Interactions and Security Reasons; JavaScript is ideal for not bogging down the Server with script(s)/coding(s) that can enhance as Web Page is served to the Visitor of the page/site.
    The XAAMP - I viewed this Development Environment Local-Computer Server (probably not the best description - but that is what I use my WAMP for) and I almost made the switch from WAMP-Server to it. Comfortability and immediate productivity is what I need right now as I feel another focal-point away (distraction) from my initial desire to and in acquiring JavaScript Skills would only overload my process in the undertaking of [for the lack of a better description at this time] Calendarizing Time.

    I'm always open to new and fresh avenues and I listen intently to absorb as much as I can ... my grey-matter's filtering process will sort it all out for me and retain a goodly portion of everything that needfully crosses my path or that I journey into.
    - Douglas

  4. #49
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    200

    for() loops

    ...well, that's the second time I've made a reply and there was an error posting it. I think I'll start typing my replies in an editor and pasting it in so that if there's ever an error again I still have a copy of what I wrote...lol.

    I must say, as I've toyed with web design through the past, when I've had questions and problems I've usually found an answer to it on this server. The WebDevelopers forum seems to be a useful tool for when problems arise. Kudos to the host, and thanks for all the people that participate in it.

    On "Calendarizing Time"....I don't know anything about that, Douglas. What's it about?
    Your friendly neighborhood Okham. -o-o-

  5. #50
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    200
    lol....well, I finally got the object constructor function to work for me. Turns out it was the way I was declaring the new item....I had typed "..new items()", when it needed to be "...new Item()" according to how I named the constructor function. Well, now I have to go through my item files again and change the statements...heheh. I must say, I've always had a limited understanding of what an object was comprised of. I see now that it has uses in this way that I can utilize in further endeavors. I'm sure it'll take some time for me to get used to it, and get used to the built in native methods that I can access. But I do thank you for introducing me to the concept. Incidentally, is there a handle or otherwise that you go by? I've never known what to call you...lol. This has certainly been a learning experience thread for me. - - okham
    Your friendly neighborhood Okham. -o-o-

  6. #51
    Join Date
    Jan 2017
    Location
    Madison, Wisconsin state
    Posts
    55
    Quote Originally Posted by okham View Post
    ... On "Calendarizing Time"....I don't know anything about that, Douglas. What's it about?
    It's what I'm referring to [currently] about phasing modern day time (keeping) into Scriptural time (keeping). Here's a screenshot of the display currently (today).

    ... I reason that if a "handle (nickname)" is desired by you for me a call of Halfwatt or ZPCS would be appropriate ...
    - Douglas

  7. #52
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,241
    The question being... what is itemno_1,itemcost_1,itempic_1,ListSelect_1,itemname_1, how have you implemented the loop, where is your data coming from, etc. Just saying it does not work can mean many things upto and including the way in which your data is derived.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  8. #53
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,241
    Also, you have to put the data in to the object constructor in the order in which the object is made, by the looks of what I created and the way you are pushing the data in, you have mixed it all up and that means problems down the line when accessing the various properties.

    1. Item Number
    2. Name of item
    3. Cost of item
    4. Image of item
    5. Selection

    is not the same as
    1. itemno_1,
    2. itemcost_1,
    3. itempic_1,
    4. ListSelect_1,
    5. itemname_1,

    This is about organising your data and how you handle things in regards to ordering the data.

    Here is a quote from my computer studies teacher from when I was at school... "You have to remember that a computer program is only as good as the person who wrote the program, bad programs are a result of bad programmers" and he was being brutally honest because some of the people in my class were... definitely face palm when it came to writing programs or their understanding of programming.

    So with that in mind, you have to understand that little things like variable names have to be standard like Item is not the same as item and any deviation in your script is going to cause errors. This is the main reason you use lowercase name conventions...

    F12 opens the console log, click on log tab and what does it list as the error message? That should be your first port of call, it will tell you allot about what you have done wrong. It is also a useful exercise in adding in to your code console.log("something to output " + variableToCheck); so you can see functions and loops working as you expect them to work and exactly what is happening.

    The idea is that you are creating and array with object like this

    Code:
    items = [
        {no:1, name:"Coffee", cost:1.99, pic:"/coffee_image.jpg", sel:"coffees"},
        {no:2, name:"Tea", cost:2.99, pic:"/tea_image.jpg", sel:"teas"},
        {no:3, name:"Syrup", cost:3.99, pic:"/syrup_image.jpg", sel:"syrups"}
    ];
    So what will really help is to see how you are storing your raw data that is being pushed in to use in the script as well as the script you are currently using.

    If your script is too large, then make more than one post...
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  9. #54
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    200

    Sort statement

    That's interesting...the console log. I never knew it existed. Well, I checked the errors on it, and it appears I've got work to do with my item files. I've got a call to display certain <div>s in each, but those are undefined in my index page...they only exist if the item is opened to look at in my "look.html" file. So I've got to figure a way around that. I've always understood the old cliche' about "garbage in, garbage out". -- On the order of my data, I did reorder the arguments in the constructor file to match how I had it in my item files. I don't know if it's important to have the longer string data first; for instance, name is the longer of the elements, so maybe I should reorder and put that first. That would take some time. Well, let me do some more work, and see what I can do with this new information. It's a learning experience. - - okham
    Your friendly neighborhood Okham. -o-o-

  10. #55
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    200

    for() loops

    Sounds like that would be an ambitious project, Douglas. Lots of work to do. All that with JavaScript?
    Your friendly neighborhood Okham. -o-o-

  11. #56
    Join Date
    Jan 2016
    Location
    Rajkot
    Posts
    2
    Here decrement for () loop example

    for var loop1 = 10 ; index > 0; index-=1
    {
    print(loop1)
    }
    Output
    // 10 9 8 7......

  12. #57
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,241
    Quote Originally Posted by jameswarner1 View Post
    Here decrement for () loop example

    for var loop1 = 10 ; index > 0; index-=1
    {
    print(loop1)
    }
    Output
    // 10 9 8 7......
    The issue here is more to do with the way the whole script has been implemented, not about decreasing a count.

    FYI, when posting any kind of code as a response or asking a question, please use forum BB Code tags (see my signature for a clue). As for your example print() is for output to a print window, not for general output. and the script is missing a few things and can be simplified too.

    Code:
    for( var loop1=10; index>0; index--) 
        console.log("Loop count = " + loop1 );
    now the test will be output to the browsers console.log window (F12 open / close) to view it.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles