SwellBen’s wins and trials

Just started recently and found this category, so I’m going to document here.

SO I just completed the Module 2, Lesson 2 challenge, where you have to draw cards from a randomly created deck… failed miserably LOL

I was super confident going in and thought i had it, but my code was littered with errors. It seemed like most of the errors came from trying to use the wrong kinds of variables in the wrong places so they were out of scope or ‘unwrapped’, not sure what that means.

I finally took Chris’ code and slowly picked it apart to get mine to work, but i have a million questions… gonna start researching the answers:

What exactly is a struct used for? (In this case it seems like just an array would work)
Where does it go? (Always outside of body view?)
Where do variable declarations go? (Why can i access some outside of body, others no?)
Why use @status? (I thought I knew, but the DECK status var in particular confuses me here)
Why use “Public vars”? (I thought i needed these to be accessible outside of a struct, etc, guess not?)
Why are underscores after an opening ( when declaring a function? (I can’t recall, gotta dig back again)
Why doesn’t my rand element version work (“wrapped/unwrapped errors”)?

I’ll see what I find and report back

Rewatched Lesson 8 as suggested and found a bunch of my answers:
What is a struct used for?

• A basic building block to represent something in your app, using: data, UI, and functions (maybe a screen or component)

• use them to group together functions

• use them to track variables outside of functions

  • variables and constants first (called “PROPERTIES” in a structure)

  • functions go next (called “METHODS” inside a structure)

Where do variable declarations go?

  • inside the struct they will be used for

Why use @status?

  • for a variable that needs to be ‘watched’

Why use “Public vars”?

Why are underscores after an opening ( when declaring a function?

So you dont have to specify argument labels within that function

Why doesn’t my rand element version work (“wrapped/unwrapped”)?

Still, I tried the whole thing over from scratch and just get so many errors, Im givinng up so i dont get too stuck

1 Like

Love it! Makes me feel like I’m not the only one that feels in the. dark on some of these lessons! lol