0

Figuring out if my code is valid

So I figured out that in order to better learn programming, I'll write my own(-ish) code for a "graduation project"– an ARPG. The first topic that is implementable with my level of knowledge, is arrays, and I figured out that an array is the way to store player character's stats. Array itself seemingly causes no trouble, but I decided to specify that each character stat is, in fact, a compound object that consists of two base objects: a character starting class base stat plus an amount of stat points a player invested in a given stat on top of that. So the question therefore is: is that piece of code where I declare stat objects, valid? P.S.: if I in fact successfully learn JS and finish this project, I'm going to release it for free and list everyone who found time to help me with it, and my gratitude in advance to every person to do so. I'm not Yandere Dev, I stick to my word, watch me :) https://code.sololearn.com/W2fQzPDNzuco/?ref=app

27th Jul 2020, 4:07 PM
μεοω
μεοω - avatar
4 Respuestas
+ 2
XXX I did, but it's really awkward to access the course while writing code, and I can't really remember things if I don't practice them, therefore this project) Thank you so much, I'll go to the drawing board and try to retain the knowledge :)
27th Jul 2020, 4:38 PM
μεοω
μεοω - avatar
+ 1
No you are totally using arrays and objects in a wrong way. And also, the declaration of objects is wrong. If you haven't done the JavaScript course please do so. Anyways see this for objects https://www.sololearn.com/learn/JavaScript/1152/ Back to using them in the wrong way, if you want to store player stats, and be able to access the stats by their name, you shouldn't use an array, Instead use an object (or in es6, you can use classes). So, for example, you can create an object constructor named Stats function Stats(endurance, faith, ........){ this.endurance: endurance this.faith = faith ........ } So then you can use the object later let player_stats = new Stats(.........) // pass the values in the paranthesis And then you can access any property of the player player_stats.faith or player_stats["faith"]
27th Jul 2020, 4:34 PM
XXX
XXX - avatar
0
But, What's your question? 🤔
27th Jul 2020, 4:27 PM
Lakshay Mittal
Lakshay Mittal - avatar
0
Lakshay Mittal god I'm dumb, sorry) Am I correct to declare an object that is supposed to consist of two other objects (and is it even possible at all), the following way: let plrVtlty = { clssBaseVtlty + plrLvldVtlty }; Just in case: plrVtlty is supposed to be a sum of values of clssBaseVtlty and plrLvldVtlty (they all are meant to hold numeric values)
27th Jul 2020, 4:32 PM
μεοω
μεοω - avatar