Ask coding questions

← Back to all posts
JS Newbie.....dont laugh
isreal (1)

Figure its something simple thats wrong but I haven't figured it out. Any guidance is greatly appreciated!

function isOldEnoughToDrink(age) {

var age=22;
var legalAge=21;
var theDrinker=age;

if (theDrinker>=legalAge){


Answered by Zavexeon (1039) [earned 5 cycles]
View Answer
Zavexeon (1039)

I made some edits.

First of all, your code to check the age is outside of the function, it should be on the inside. You don't need to declare age either, you just need to call the function like this, isOldEnoughToDrink(ageHere);.

Fixed code:

function isOldEnoughToDrink(age) {
  var legalAge = 21; //'const legalAge = 21' is preferred 
  var theDrinker = age;
  if (theDrinker >= legalAge) {
  } else {

ash15khng (682)

What's the question and the intended output?


It seems to work and print true (ignore the undefined that comes after it). Is that not what you expected?