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
Fuad Adetoro
6,490 PointsWould this ever work?
Just wondering if this will ever work or if someone can make this better and work because that would be pretty cool, i'm still a begginer to JavaScript.
var name = prompt("what is your name?");
alert("Hi ," +name);
if (name) {
console.log("got your name " +name);
console.log("How are you " +name);
} else {
console.log("Come on give me your name!");
}
var null {
if {
+name = "null";
console.log("Come on give me your name");
}
else {
+name = "Fuad Adetoro";
console.log("Welcome sir");
}
}
if(null) {
console.log("Come on give me your name!");
} else {
console.log("");
}
/*Creators name is Fuad Adetoro hence the reason when the +name variable is equal to
Fuad Adetoro he gets a console.log message saying Welcome sir*/```
1 Answer
Ricardo Hill-Henry
38,443 PointsShould work if you make null = to a function containing the code opposed to var null {, I don't think that works, because it's not initializing null to anything. Then just run the null function below, and that will run the code in between. You also need a condition in the if statement inside null, inside the parenthesis; such as if(name == "null") that runs the code only if the user doesn't provide a name. The way your if statement is written, it won't compile. It will likely read it as if you're using that entire piece of code as your conditional statement, causing an error. You also use closing parenthesis in your else statement, but never opened any.
Have to go now.
Fuad Adetoro
6,490 PointsFuad Adetoro
6,490 PointsThanks for your reply i will try them all now