Jump to content

can someone help me with a javascript game?

iLostMyXbox21

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

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to comment
Share on other sites

Link to post
Share on other sites

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

✧・゚: *✧・゚:*  Quote for a reply  *:・゚✧*:・゚✧

 

✧・゚: *✧・゚:*   Ask for discord   *:・゚✧*:・゚✧

Link to comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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. 

OSINT 
Link to comment
Share on other sites

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

×