0
x = 10
function lol(){
    x = 5
}
function rofl(){
    alert(x)
}

In the rofl() function, how can i make the alert popup number 5? help me please I'm so noob trying to figure this out for 4 hours now :S

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
Maria
  • 3,455
  • 7
  • 34
  • 47

2 Answers2

4

You're close. Really, really close.

The only problem is that you're not actually invoking either of the functions. This is all you're missing:1

lol();
rofl();

Working demo: http://jsfiddle.net/mattball/VsGWe


1 Well, that and some semicolons.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • 1
    Semicolons are not required in Javascript (google the infamous Javascript semicolon insertion rule) but many think you should never omit semicolons. – nalply Aug 04 '12 at 18:52
  • 1
    "Many" includes me, if for no other reason than [the `return` gotcha](http://stackoverflow.com/q/8528557/139010). Don't like semicolons? Write Python or CoffeeScript. – Matt Ball Aug 05 '12 at 00:06
  • Of course, you are right. The optional semicolons is one of the huge misfeatures of JavaScript. Even if you terminate ALL statements with semicolons the return gotcha will trip you up. That's why I decided to drop all semicolons for my personal projects and be careful of different gotchas like ;[1, 2, 3].foreach(f) as mentioned in http://blog.izs.me/post/2353458699. For projects I share with other people I go with the crowd and obediently put semicolons where other expect them. – nalply Aug 05 '12 at 09:35
0

You dont have to do anything other than call the functions. You have set them up properly, but if you dont call them then nothing will happen.

x = 10
lol();
rofl();

function lol(){
    x = 5
}
function rofl(){
    alert(x)
}

​Live DEMO

Josh Mein
  • 28,107
  • 15
  • 76
  • 87