Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
iLostMyXbox21

can someone help me with a javascript game?

Recommended Posts

Posted · Original PosterOP

so i’m making a game where basically, you click the advance one week button, get a paycheck, and have to buy things (like a house, car, etc)

 

but it i can not figure out the buying portion. it does not take the money from the total. also, how can i make it to where it will not go in negatives?

 

https://hastebin.com/wucujopuqi.php


Discord: iLostMyXbox21#4649

 

 

~~~~ SpEcS ~~~~

CpU: rYzEn ThReE TwEnTyTwO hUnDrEd G

GpU: vEgA EiGhT

RaM: OnE StIcK ThReE ThOuSaNd MeGaHeRtS DdRFoUr

CaSe: DiYpCf2

Link to post
Share on other sites
Posted · Original PosterOP

update: it didn’t save my full code. so here is the site i use (w3schools)

 

https://www.w3schools.com/code/tryit.asp?filename=G1DLTDVN1K3V

 

edit: heck, it didn’t save. i’ll update when i retype it


Discord: iLostMyXbox21#4649

 

 

~~~~ SpEcS ~~~~

CpU: rYzEn ThReE TwEnTyTwO hUnDrEd G

GpU: vEgA EiGhT

RaM: OnE StIcK ThReE ThOuSaNd MeGaHeRtS DdRFoUr

CaSe: DiYpCf2

Link to post
Share on other sites

i think i can see a problem already, you always show the result of week*857 no matter what happens with the value of var money?

basically the element "money" has no ties to the variable "money"


MSI GX660 + i7 920XM @ 2.8GHz + GTX 970M + Samsung SSD 830 256GB

Link to post
Share on other sites

I'm not following.

The code i  the w3schools editor is working as intended. You get 858 $$$ every week. Is that not what you want?


Ryzen 5 1600 @ 3.9 Ghz  | Gigabyte AB350M Gaming 3 |  PaliT GTX 1050Ti  |  8gb Kingston HyperX Fury @ 2933 Mhz  |  Corsair CX550m  |  1 TB WD Blue HDD


Inside some old case I found lying around.

 

Link to post
Share on other sites

You are currently getting the total for the new week by multiplying the week number by the amount per week. This means that if I get $800 in week one and spend $800 then in week two your calculation will give me 2*800 rather than an extra 800 on top of my balance (leaving me with 800, not the 1600 I currently get).

 

Your "advance one week" button should just be adding the weekly amount to the balance that you have, and ignoring the week it is on. As for preventing negative numbers...that's trivial once you have a balance variable because you simply check that you have enough money in your balance to purchase the item you want, and you prevent it if you don't have enough, meaning it is impossible to ever get below 0. 

Link to post
Share on other sites

Yeah as others have said, you need to have a balance Var, and add or subtract from that. The week you are on shouldn't matter - the weekly amount should just be added on to your current balance. 


console.log("It's not a bug – it's an undocumented feature.");
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×