• Question
  • I don't know what it's called but I need help with it

Do you understand. it is 12:00 AM I am not dealing with this

Mellow
imma kill two birds with one stone on this
varrience probably has a better way but...

so anyways here how to for loop

for(var i = 0; i < 5; i++){
}

  1. the var i = 0 means your making a variable called i which starts at 0
  2. the i < 5 means the loop keeps repeating while i is less than 5
  3. the i++ means i increases by one every time the loop repeats
    SO, in total, the loop repeats five times.
    now, to incorporate with arrays:
    for(var i = 0; i < array.length; i++){
    }

    you'll notice its the same as before, except for part two where it now says i < array.length instead of i < 5
    this means that the for loop repeats array.length times, which means it repeats once for each object/achievement in the array

so now we can go through each achievement in the array by using array[i](the ith object in the array, and since i is changing once for each object in the array, we cover all the objects)
to sum it up you'd need something like this:
var numCompleted = 0;
for(var i = 0; i < achievements.length; i++){
if(achievements[i].completed === true){
numCompleted += 1;
}
}

again, hope this helps and im sure varrience has a better way of doing this but until then your welcome

    ackvonhuelio hey ack I need some help. How do I come off as stern but not angry or pissed? I know you cannot type emotion however I know that you have done this before. So please help a brother out.

      Mellow possibly... not sure exactly what your trying to do, but i'll give 2 examples to try and answer what your trying to do, the

      • first is to add a property that keeps track of that in the object that will update manually, unlike arrays objects don't have a .prototype.length attribute

      • second is to encase multiple arrays of objects containing a Boolean on if they have been unlocked
        the two examples will be showcased below for those who want to learn

        var  obj = {
        pro: true,
        noob: false,
        achivements: 1
        total: 15
        }
        // we can then update it at any time a new achievement is unlocked
        var loser = true;
        if(loser && !obj.noob){obj.noob = true; achivements++}
        console.log("you have "+obj.total-obj.achivements+" left keep it up!")
        // the second way is below here which is basically what Ack did
        var accomp = [
        {title: "Ruiner", unlocked: false}
        {title: "Participation Award", unlocked: false}
        {title: "Secret Customer", unlocked: true}
        ];
        // to calculate how many achievements we have left we must iterate through the Array
        function accompLeft(){
        var left = accomp.length; // stores total achievements
        for(var i = 0; i < accomp.length; i++){
        if(accomp[i].unlocked){left--} // here we access an accomp [ index ] and a .property from that index 
        }
        return(left)
        } 

        just stop f@cking arguing all the time goddammit
        i am not going throught 48 posts >:(

          Varrience well... the last one i wrote was pseudo code so it won't actually run so if your looking for something to play around with and understand how it works this is the better example of what i was showing off.... not sure if i should remove the previous post though

          var  obj = {
          pro: true,
          noob: false,
          achivements: 1,
          total: 15
          }
          // we can then update it at any time a new achievement is unlocked
          var loser = true;
          if(loser && !obj.noob){obj.noob = true; obj.achivements++}
          console.log("you have "+(obj.total-obj.achivements)+" left keep it up!")
          // the second way is below here which is basically what Ack did
          var accomp = [
          {title: "Ruiner", unlocked: false},
          {title: "Participation Award", unlocked: false},
          {title: "Secret Customer", unlocked: true}
          ];
          // to calculate how many achievements we have left we must iterate through the Array
          function accompLeft(){
          var left = accomp.length; // stores total achievements
          for(var i = 0; i < accomp.length; i++){
          if(accomp[i].unlocked){left--} // here we access an accomp [ index ] and a .property value from that index 
          }
          return(left)
          }
          console.log("you have "+accompLeft()+" left keep it up!")

            ackvonhuelio Varrience
            Yoo thank you guys so much! This helps a great ton!
            Unfortunately, my dumb little brain isn't quite able to grasp what's going on in Varrience's examples, but hopefully I'll be able to understand it later. Still, it means a lot, thank you guys!

              INTERNECION Number one thing not to do when you don't want to sound pissed is to not use all caps. All caps 99% of the time mean that you are shouting, and if you're shouting, it's going to be assumed that you are indeed angry. It especially does not help you when you combine a warning with all caps. It comes across more as an angry threat than a warning. Instead, use italics when you want to put emphasis into a certain part. (yea I used caps for 2 words that one time then remembered the tilted I was a thing so 👍)

                Oh and, using words that refer to the offender is also usually unhelpful. For example, you should say
                "This goes against our rules, please don't do that again"
                Instead of
                "You are breaking our rules, don't do that again"

                Mellow Well I usually use all caps for emphasis and not for yelling. I mean what will I yell at the screen for? It isn't like it just booted up my i.p. adress from out of nowhere. Haha

                  alright then. But did you see my explanation about the controversy as well?

                  INTERNECION eh fair, but it's still best to not use all caps, as long as there are ways to emphasize in other ways. (if there aren't ways to emphasize, I usually a d d s p a c e s in between my words, but that's annoying so it's fine if there's no options)
                  And the controversy
                  Uh
                  many words, yes

                  Oh also also-
                  Full sentences with all caps are worse than single words with all caps, cuz then you're going to look like you're really pissed off. plus if I were to emphasize an entire sentence, its just kinda... a normal sentence looking different, rather than it actually putting any emphasis in
                  Though it can work for much shorter sentences
                  emphasizing long sentences doesn't do much

                  Mellow ah i see... well you should be able to grasp my example by putting in into a new project or basically almost any JS interpreter and start playing around with what I've got (make sure you use the 2nd iteration of my example as that one you can run), my 2nd example is basically like Ack's... I don't think its that much more of a stretch of a concept or just go off of what Ack said as well if you plan to learn more on your own, Good Luck!

                  ackvonhuelio uh it looks like the for loop isn't quite working, I'm testing it with hidden achievements and it just shows as 0, even though there's a few

                    Mellow well did you format it properly? the way Ack show it is object array and i'll give a smaller demo of what he did that way it should be followable

                    // This is a DEMO please read comments if your stuck or confused
                    var accomp = [
                      {
                        title: "new world", // a title of the achivement optional properties like description can also be added
                        unlocked: true // the property to look for if we unlocked the achivement
                      }, // , <= is important since this is an array
                      {
                        title: "pro",
                        unlocked: false
                      },
                      {
                        title: "gamer",
                        unlocked: true
                      }
                    ];
                    // here we are going to count how many achivements we have left
                    console.log(accomp.length) // <= this will give us how many achivements we have
                    var unlocked = 0; // keeps track of the current achivements we have
                    for (var a = 0; a < accomp.length; a++) { // here we iterate through the array
                      if (accomp[a].unlocked === true) { // === true doesn't need to be there if's already look for a boolean outcome
                        unlocked += 1; // we add here how many is unlocked
                      }
                    }
                    // here is something more complex we know how many achivements we unlocked and how many we have,
                    // but how do we show that as output since "-" statements are illegal in console.log statements
                    var achivementsLeft = accomp.length - unlocked; // this makes it so no () are needed
                    console.log("You have " + unlocked + " achivements so far\n There's " + achivementsLeft + " left go get em champ")
                    // this is how it would be done given that you didn't want to declare a variable for a result
                    console.log("You have " + unlocked + " achivements so far\n There's " + (accomp.length - unlocked) + " left go get em champ")

                      yeah none of us can actually understand varriance but just go with whatever he's saying its probably right.

                      Mellow
                      for loops are suuupeeerr useful, so definitely take the time to actually learn how they work and don't just copy and paste

                      INTERNECION

                      INTERNECION lol really what did i do because all i type was

                      2kChubz Disrespectful??? nah bro went to far

                      2kChubz yea you get it lol

                      2kChubz no he doesnt care about noitif he just want points I love how he lies how he don't care about points but he likes his own post

                      Chat