Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascripting Exercise 2 - Variables #2644

Open
caro-turnbull opened this issue May 9, 2023 · 1 comment
Open

Javascripting Exercise 2 - Variables #2644

caro-turnbull opened this issue May 9, 2023 · 1 comment

Comments

@caro-turnbull
Copy link

I'm stuck on the second exercise. Instructions are:
Create a file named variables.js.
In that file declare a variable named example.
Make the variable example equal to the value 'some string'.
Then use console.log() to print the example variable to the console.
Check to see if your program is correct by running this command:
javascripting verify variables.js

So,
I've created a file called variables.js. I open that file with:
nano variables.js

Then I type this in the file: (this where I think I've missed something or messed up??????)
let example
const example = 'some string'
console.log(example)

Save and exit. Then I verify and I get this error...

Error: Command failed: node "/Users/carolineturnbull/lighthouse/javascripting/variables.js"
/Users/carolineturnbull/lighthouse/javascripting/variables.js:2
const example = 'some string'
^

SyntaxError: Identifier 'example' has already been declared
at Object.compileFunction (node:vm:355:18)
at wrapSafe (node:internal/modules/cjs/loader:1022:15)
at Module._compile (node:internal/modules/cjs/loader:1056:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47

at ChildProcess.exithandler (node:child_process:326:12)
at ChildProcess.emit (node:events:369:20)
at maybeClose (node:internal/child_process:1067:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {

killed: false,
code: 1,
signal: null,
cmd: 'node "/Users/carolineturnbull/lighthouse/javascripting/variables.js"'
}

@LalitAswal
Copy link

@caro-turnbull bro
in your code
let example const example = 'some string' console.log(example)
it should be
const example = 'some string' console.log(example)
filrst you have declare example variable with let in 1st line then in 2nd line you declaring it with const
use let or const for same variable name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants