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

running javascript from external file

hie guys pretty stuck here need some help. i am doing javascript basics and i am doing my practice on notepad++ and brackets. i am only able to use the alert("whats your name") and prompt(), but thats far as it goes. if i write the if else statement or function nothing appears on my preview or browser.

2 Answers

Hi Vellon,

I can't be 100% from your explanation but you need to call functions, they don't run automatically.

Please can you share the code you're having issues with.

how do i call a function or even a variable. here is my code if (day < 7) { greeting = "happy week"; }

The code you've supplied is a conditional (if statement) and inside that you have a statement which sets the variable greeting to a string with the value "happy week".

Let's say you're using that code to set an alert. You might do something like this.

var greeting = "Hello there!"; // Here I have defined the variable greeting to say "Hello there"
var isWeekend = true; // I have defined a variable that lets us know if it is the weekend and I have set it to true
if ( isWeekend === true ) {  // Now I have used an if statement to change the greeting if it is the weekend.
    greeting = "Hello there! It's the weekend!!!";
}
alert(greeting); // Now I have created an alert that will display the value of the variable greeting.

Only when I use the alert() method does anything happen.

Hopefully that helps :)

thanks rhysdamagnez iwas able to see where the problem was