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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Introducing Conditional Statements

Lyndsay Norris
Lyndsay Norris
1,907 Points

whats wrong with my code?

var = answer if ( ) { prompt('What is the best programming language?'); }

app.js
var = answer
if ( ) {
prompt('What is the best programming language?');
}
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>

2 Answers

Hey Lyndsay,

To be honest, there's quite a lot wrong with your code. My suggestion is to go back and rewatch the videos.

When you're creating variables, you always have var variableNameHere = someValue. You never have var = variableNameHere. The variableNameHere should be answer and someValue part needs to be the prompt because once a user inputs something into the prompt and hits enter, it will put that information inside of answer.

var answer = prompt('What is the best programming language?');

Hi Lyndsay,,

  1. Var is used to declare a variable, you only need the = when you want to assign a value to it.

  2. The if statement is used to conditionally do something so it needs a condition which will evaluate to true or false.

  3. You need to store the response to the prompt (question) in the variable named answer so you can do something with it later.

  4. Watch the video again with this in mind.