Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Whats wrong with my JavaScript code?

var QsLeft = 3;
var questions= ("[There are " + QsLeft + " questions left]");
var ask= prompt(" sup? " + questions);
var ask2= prompt('how are you?' + minusOne());


function minusOne(){
  QsLeft=-1;
 return(questions);
}
Cooper Runstein
Cooper Runstein
11,850 Points

Format as code next time!

var QsLeft = 3; 
var questions= ("[There are " + QsLeft + " questions left]"); 
var ask= prompt(" sup? " + questions); 
var ask2= prompt('how are you?' + minusOne());

function minusOne(){ 
    QsLeft=-1; 
    return(questions); 
}

2 Answers

Cooper Runstein
Cooper Runstein
11,850 Points

You're reassigning the value of Qsleft in your function, you should be doing something closer to:

 QsLeft -= 1;

I changed QsLeft to -=1 and it's not working, is there something else I'm not catching?

Cooper Runstein
Cooper Runstein
11,850 Points

Well I'm not entirely positive what it is you want this code to do. I recommend you add some comments to your code explaining what you expect each line to do, and include one or two lines at the beginning describing what you want this piece of code to do, post it as a comment, and I can help you figure out where you're going wrong. Or in the process of thinking each line over, you might figure out whats going wrong on your own.