-4
var age1 = 30;
        if(age1 >= 13 && age1 <= 19){
            message = "You are a teenager";
            }else{
                message = "You are not a teenager";
            }

This code is pretty self explanatory, but when I run it in html It does not work, I don't know why. It does not give me any of the messages when run in HTML.

  • where do you use `message` ? – Devsi Odedra Feb 14 '19 at 10:51
  • what output did you expect? – Karim Feb 14 '19 at 10:51
  • 1
    Have you tried doing `console.log("text here");` instead of `mesage = "text here"` – nick zoum Feb 14 '19 at 10:52
  • I expected it to output "You are not a teenager" because age1 is not within the 19-13 range. – Jake Watson Feb 14 '19 at 10:52
  • @JakeWatson — But your code assigns the string to a variable, it doesn't do anything to output it. – Quentin Feb 14 '19 at 10:53
  • So you need to log this message. Currently you are only assigning value to the variable. For example `console.log(message)` – Suule Feb 14 '19 at 10:53
  • *Warning*: `message` is an implicit global, globals are best avoided 99.9% of the time, and implicit globals are forbidden [in strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) which you should be using. – Quentin Feb 14 '19 at 10:54

1 Answers1

2

Use console.log to print the message

var age1 = 30;
if (age1 >= 13 && age1 <= 19) {
  message = "You are a teenager";

} else {
  message = "You are not a teenager";

}
console.log(message)
ellipsis
  • 12,049
  • 2
  • 17
  • 33