skip to Main Content

When I try to call the function I created (see code below), it throws an error stating that "Jon is not defined". Why is it saying that? How is an argument for a function I’m trying to call undefined?

function greeting(person, hour, minutes) {
    time = ((hour+12)*1000)+minutes
    if (person = "Count Dooku") {
        console.log("I'm coming for you, Dooku!")
    }
    else {
        console.log("Good day, " + person + "! " + "It is currently" + time)
    }
}

console.log(greeting(Jon, 1, 13))

And the error is this:

Uncaught ReferenceError ReferenceError: Jon is not defined
    at <anonymous>         
 
    at Module._compile (node:internal/modules/cjs/loader:1267:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at executeUserEntryPoint (node:internal/modules/run_main:83:12)
    at <anonymous> (node:internal/main/run_main_module:23:47)
Process exited with code 1'

I tried fiddling around in trace playground to see if I could alter the code and get it to work, but I’m pretty certain this is the basic setup for creating and calling a function. I don’t even know what I would change.

I am using VS Code if that makes any difference. I don’t have much experience with it, so if it’s some missing extension or something I would have no idea.

2

Answers


    1. try "jon" instead of jon. without quotes, it is assumed to be a variable, but there is no variable jon defined.

    2. if (person = "Count Dooku") { this is not a comparison, but an assignment. You most likely wanted to compare, using ==

    Login or Signup to reply.
  1.   function greeting(person, hour, minutes) {
       var time = ((hour+12)*1000)+minutes
         if (person = "Count Dooku") {
          console.log("I'm coming for you, Dooku!")
        }
        else {
        console.log("Good day, " + person + "! " + "It is currently" + 
        time)
        }
       }
    
      greeting('Jon', 1, 13);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search