Willchill Does JavaScript! :D

Willchill

Blocktopia's Official Octopus
Joined
Sep 9, 2011
Messages
450
Reaction score
1,017
Points
93
Heya!

I've been learning a few coding languages off of Codeacademy recently. One of my first major projects I've chosen to do is a text-based adventure RPG game. I'm too lazy right now to go into details about it, so try it yourself!

http://labs.codecademy.com/BNFf/21#:workspace

To play you must click the "Run" button in the top-right corner of the white box (around the top-middle of your screen). Then, read the text that appears in the black box on the right and answer the questions in the box. So far there are 6 different endings. :D

Happy Coding~

Willchill
 
  • Like
Reactions: Infected_alien8_

TubaRiver

Masterful
Donor
Joined
Aug 6, 2011
Messages
278
Reaction score
317
Points
43
Not bad.

Here's some cool tips that might improve your code.
Use some forms of validation when asking for user-input. That way, it becomes more logic friendly and you can re-use their input at a later time for more advanced methods.

Also, instead of using a barrage of if series, switch to cases. That way you only have to call on 1 'if' for a hundred different cases!

variation 6 btw.
 

Willchill

Blocktopia's Official Octopus
Joined
Sep 9, 2011
Messages
450
Reaction score
1,017
Points
93
Not bad.

Here's some cool tips that might improve your code.
Use some forms of validation when asking for user-input. That way, it becomes more logic friendly and you can re-use their input at a later time for more advanced methods.

Also, instead of using a barrage of if series, switch to cases. That way you only have to call on 1 'if' for a hundred different cases!

variation 6 btw.
I tried doing that with character names, but wasn't sure how to include variables in console.log strings.
(E.G: The user would answer a prompt asking for their username. Their entry would be userName [a variable]. I tried console.log("Welcome, userName") but that didn't work, it only printed "Welcome, userName" to the console.
(I forgot quotation marks lol.)

As for the barrage of if series, are you recommending using a function? Could I please have an example of a function using booleans? x3

Thanks for the feedback. :D
 

TubaRiver

Masterful
Donor
Joined
Aug 6, 2011
Messages
278
Reaction score
317
Points
43
Try it more dynamic/OO style code.

Code:
console.log("welcome," + userName);
use your console log for the output statement and then add your variable outside the string, but still within the statement. the plus sign means you want to combine the two, for the output.

eh i ment more of a javascript switch statment to hold the cases, but yeah a function wouldnt be bad.

Im more adept to Java and C++ so forgive the horror of non-nicety in my javascript.
Code:
function password()
{
    var inputPassword = document.getElementById("userinputtedpassword ");
    var validPassword = document.getElementById("thevalidpassword");
 
      while inputPassword.value !== " " && inputPassword.value == validPassword.value {
        return true;
        }else{
        return false;
}
Basically here's whats going on.
Create a new function called password.

create 2 variables inputPassword (where you want a user to obviously input something)
and validPassword (this password is the correct answer, you want the input to equal this)

while the input DOES NOT equal null (if they left it blank) AND while the input EQUALS the validPassword. its good return true and keep going. If not, its false and will force the user to keep trying until they get it right.

This can be simplified and validated even further, for example, if you want a password to equal 'x' amount of characters or only accept certain characters etc etc.

Thats a function for booleans in a nutshell. Again, forgive the javascript messy-ness.