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 trialLyndsay Norris
1,907 Pointswhats wrong with my code?
var = answer if ( ) { prompt('What is the best programming language?'); }
var = answer
if ( ) {
prompt('What is the best programming language?');
}
<!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
Marcus Parsons
15,719 PointsHey 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?');
Michelle de Haan-Pitman
2,310 PointsHi Lyndsay,,
Var is used to declare a variable, you only need the = when you want to assign a value to it.
The if statement is used to conditionally do something so it needs a condition which will evaluate to true or false.
You need to store the response to the prompt (question) in the variable named answer so you can do something with it later.
Watch the video again with this in mind.