#how to run code in the terminal?
58 messages · Page 1 of 1 (latest)
not script ,coder
code
how to run terminal?
how to run code in the terminal?
How are you running it?
i was running it previously with debug console until i realized it was the debug console and not the terminal
node function.js
Is that path correct? Does the file exist? Did you save it?
Path doesn’t look correct
You’re in your “home” directory, not desktop (in the terminal)
cd C:\Users\ptara\Desktop\html\ and\ java\
node function.js
ohh is there a backslash between spaces??
yes. it's called an escape character. you'll run into it a lot
hah. I fail. use quotes
where
cd "C:\Users\ptara\Desktop\html and java"
node function.js
makes the entire string (including spaces) a single argument
it makes it 1 string basically or no?
yes. there's only a single argument, instead of argument 1 being C:\Users\ptara\Desktop\html, argument 2 being and, and argument 3 being java
P.S.:
Despite their similarity in name, Java and JavaScript are different languages and are not compatible with each other. This is a JavaScript server, but there are likely many Java-specific servers out there.
alr thanks now i need to figure out why my function isnt returning
wait so i have to do this every time??
like with every new project and with every time i want to run the code?
You just need to be in directory where your .js file is. Which is what you've done with cd {path to directory. This sets which folder aka directory you are in, in your cmd. Since you are in folder where your js file is. Node is able to find it and run it
Typically you open that folder in vscode so it sets the path when you open a terminal.
yea i found out whilst messing with the explorer
It is returning. You just aren’t doing anything with the return value.
Right. console.log() to display
on other editors it would show the 20? or is this a feature that isnt in vscode
That’s DevTools console
Like it showed undefined for the previous line, it always shows the return value of that expression
return of your function function1() is number '20'. But you or we can't see any of that because once you run your .js file with node, your program successfully runs but it doesn't output anything to the console. That's why you need use 'console.log() to log a output to a console.
so its there but its not showing?
Yes. The return value of the function is 20
Assign it to a variable, log it, do whatever you want with it. But do something..
how would i make it visible in terminal? console.log(function1) ?. ( idk how to type in the code way)
Your almost there. I recommend you keep experimenting with your code.
u spent that whole time typing just to say that 😭 . i was hoping you would tell me lol. i will be experimenting
I was about to tell you what you needed to type but figured you'd need to do this on your own.
yea i realized that i needed to log the return otput
if thats how u would say it
(function1())
Anyways. Good luck on your JavaScript learning journey. It's a great journey and I hope you keep at it