• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Script not working?

Status
Not open for further replies.
Level 17
Joined
Dec 11, 2014
Messages
2,003
Hey there hive! I Hope you have a nice day.
It's the second day I'm trying to learn some ways to write scripts, So I'm a n00b.
Anyways, on one of my JavaScript Scripts, I encountered a Problem:

The main Idea is supposed to be Something like Hidden tags, To show screenshots when a button is clicked, and Hide when clicked again. I Used some variables and If/then/elses, they didn't work out... So any help would be appreciated.


The button things
Code:
<button onclick="displayScreenshots()">Screenshots</button>
The script:
Code:
function displayScreenshots() {
    var boolScreenies = "false";
    var ScreenshotString;
    if (boolScreenies = false) {
         boolScreenies = "true";
         ScreenshotString = "Daiee"
    } else {
         boolScreenies = "false";
         ScreenshotString = "";
    }
    document.getElementById("ScreenshotsHere").innerHTML = ScreenshotString;
}



And don't hurt me, I'm a noob :D

I also tried inspecting the Hidden tags in the Hive, understood Nothing :(
 
You have three different errors.

First of all, you are mixing the assignment operator (=) and the equality operator (==, but you'd usually want to use ===, to be extra safe).

The second issue is that you are using a string, but comparing it to a boolean.
"false" is a string, false is a boolean.

Finally, the last error is a logical one - you are checking if a variable you just set at the beginning of the function call is a certain value.
You just set it - the value will always be "false".
You probably meant to use a global variable, just declare it outside of the function.

With all of these changes, it should be something like this:
JavaScript:
var boolScreenies = false;

function displayScreenshots() {
    var ScreenshotString;
	
    if (boolScreenies === false) {
         boolScreenies = true;
         ScreenshotString = "Daiee";
    } else {
         boolScreenies = false;
         ScreenshotString = "";
    }
	
    document.getElementById("ScreenshotsHere").innerHTML = ScreenshotString;
}
 
Status
Not open for further replies.
Back
Top