15,907,395 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 13257242 (Top 31 by date)
Member 13257242
2-Sep-17 10:14am
View
I already have updated my question. No answers.
Member 13257242
1-Sep-17 23:01pm
View
OK! Added some code
Member 13257242
4-Aug-17 10:20am
View
It still doesn't work. I fixed the code a bit and added this into each of the buy functions:
function buymagikarp() {
if(coins >= 100 ) {
swal("Success", "You bought 1 magikarp!", "success");
coins -= 100;
document.getElementById("p1").innerHTML = "Coins: " + coins;
localStorage.setItem('coins', coins);
} else {
swal("Error", "Not enough balance", "error");
}
if(pokemon1 == "") {
pokemon1 += "Magikarp";
localStorage.setItem('Magikarp', pokemon1);
}
if (localStorage.getItem("pokemon1") === null) {
localStorage.getItem('pokemon1');
}
}
I really don't understand why it doesn't work. You probably already understand my skill level of this type of code, but I cannot justify why my code doesn't work. Please help!
Member 13257242
3-Aug-17 14:38pm
View
"won't work" means I still get the same error: here is my website if you want to check it out and see the error pokemonupgrade.000webhostapp.com
Member 13257242
3-Aug-17 14:22pm
View
Even after defining JSONReadyUsers outside of getName2 BOTH in the script tag and in the script.js, It still won't work.
Member 13257242
3-Aug-17 14:19pm
View
Deleted
Oh I get it xd xD
Member 13257242
3-Aug-17 14:19pm
View
Deleted
?scratching head?
Member 13257242
3-Aug-17 14:16pm
View
Deleted
oh sorry <
Member 13257242
3-Aug-17 14:15pm
View
It gives me the error:
Uncaught ReferenceError: JSONReadyUsers is not defined
at buymagikarp (script.js:35)
at HTMLInputElement.onclick (battle.html:131)
I'm sure this means that the Jquery is not working. Here is the tags that I put inside of the battle.html :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>&script type="text/javascript">function getName2 {
var JSONReadyUsers = JSON.stringify(pokemonchosen);
localStorage.setItem('pokemonchosen', JSONReadyUsers)
}</script>
Member 13257242
3-Aug-17 11:37am
View
And also, pokemonchosen starts out at undefined, so when they buy a pokemon everything in the if statement should be executed correctly?
Member 13257242
3-Aug-17 11:34am
View
Where would I put this? inside or outside of the if statement?
Member 13257242
2-Aug-17 13:41pm
View
I omitted code from the question that I thought was not needed.
Member 13257242
1-Aug-17 13:25pm
View
Which HTML content? To display the coins variable, I am using a paragraph with an id of p1 to display. How would I change that? it is document.getElementById('p1').innerHTML = "Coins: " + coins;
Member 13257242
1-Aug-17 12:01pm
View
with tags of course, for some weird reason codeproject isn't displaying the tags.
Member 13257242
1-Aug-17 12:00pm
View
body onload="getName();"
Member 13257242
1-Aug-17 11:56am
View
is the code I am using to start up the LocalStorage.
Member 13257242
1-Aug-17 11:56am
View
How would I change the localStorage setter? With a while loop? I am using this code to start the localstorage:
Member 13257242
1-Aug-17 11:12am
View
Even after removing var coins; , it still won't deplete
Member 13257242
1-Aug-17 11:07am
View
I am defining coins outside at the top of the code.
var coins = 1000;
Member 13257242
1-Aug-17 10:54am
View
Thanks for the answer ProgramFox, it really helped!
Member 13257242
1-Aug-17 10:54am
View
After tweaking the code a bit, I took a step backward and a step forward. I added in local storage:
function getName() {
var coins;
if(localStorage.getItem('coins') === null) {
localStorage.setItem('coins', coins);
} else {
coins = localStorage.getItem('coins');
}
document.getElementById("p1").innerHTML = "Coins: " + coins;
}
Now, the coins actually deplete, and they save after page reload but they still always show up as 1000 even in the console when I type in coins it shows that they depleted? This is honestly really confusing to me.
Member 13257242
1-Aug-17 10:52am
View
After tweaking the code a bit, I took a step backward and a step forward. I added in local storage:
function getName() {
var coins;
if(localStorage.getItem('coins') === null) {
localStorage.setItem('coins', coins);
} else {
coins = localStorage.getItem('coins');
}
document.getElementById("p1").innerHTML = "Coins: " + coins;
}
Now, the coins actually deplete, and they save after page reload but they still always show up as 1000 even in the console when I type in coins it shows that they depleted? This is honestly really confusing to me.
Member 13257242
31-Jul-17 13:23pm
View
Here are pics: http://imgur.com/a/GsEJF http://imgur.com/a/SJSbM http://imgur.com/a/06Ofx
Member 13257242
31-Jul-17 13:17pm
View
Thanks for the answer! Although I understand what you're saying, I don't know how to apply it to my code? For example, should I use prompts, buttons, or whatever? I am using buttons but when they click on the button to choose a pokemon, it just says Pokemon Chosen: null, I really don't get it. I'll likely take screenshots and send them to you so you can review them and see what's wrong.
Member 13257242
31-Jul-17 12:35pm
View
@ProgramFox , No, but I changed the code:
var pokemonchosen;
var coins = 1000;
var pokemonagainstTutorial = "Magikarp";
//HP For Pokemon - Start
var hpmagikarp = 100;
var hpcharmander = 100;
var hpbulbasaur = 100;
var hpsquirtle = 100;
//HP For Pokemon - End
function move() {
if(localStorage.getItem('pokemonchosen') === null) {
localStorage.setItem('pokemonchosen', pokemonchosen);
} else {
pokemonchosen = localStorage.getItem('pokemonchosen');
}
document.getElementById("p1").innerHTML =
"Pokemon chosen: " + pokemonchosen;
}
Member 13257242
31-Jul-17 11:54am
View
I edited the code a bit:
<added to question>
Member 13257242
23-Jun-17 15:19pm
View
Sorry for no code, but code wouldn't really help here. I just need a straight up answer. thanks guys. :)
Member 13257242
16-Jun-17 14:18pm
View
Thanks bro!
Member 13257242
16-Jun-17 13:27pm
View
I don't know why this is not*** working.
Member 13257242
13-Jun-17 14:57pm
View
Likely going to do what Richard said but that could work to.
Member 13257242
13-Jun-17 13:22pm
View
Oh! Thanks for the reply, really helped me out :)
Show More