So, I have an HTML button hooked up to run the function shown in the code above, and I've tried many ways like using different toggle functions such as bool = bool ? false : true; but none work. I've tried to insert the hideToggled = !hideToggled in other places, like both the if functions, or below the if functions, but neither seems to work. Any help would be extremely appreciated!
You are assigning your variable true/false value in the if blocks
if (hideToggled = true)
will result in hideToggled to be assinged the value true
Check out the working code below:
let hideToggled = false
let hideButtonText = ''
function toggleHideShow() {
hideToggled = !hideToggled
if (hideToggled) {
hideButtonText = 'Show'
} else {
hideButtonText = 'Hide'
}
}
toggleHideShow()
console.log(hideToggled, hideButtonText)
toggleHideShow()
console.log(hideToggled, hideButtonText)
toggleHideShow()
console.log(hideToggled, hideButtonText)
toggleHideShow()
console.log(hideToggled, hideButtonText)