very new to coding and decided to start a project of mine. I watched a video on how to get it set up and started but after tinkering with it a little, I realized it was Java, not JavaScript. (Hey, i'm a noob at this) and I wanted an easier way to implement new things. this is what my main script looks like.
public void onMessage(String Message){
if(message.equals("Apples"){
sendMessage("You said apples!")}
else {
if(message.equals("Oranges" //any text
){
sendMessage("you said Oranges and" //what they put for any text
)
...
Is there a way to take the bit that says Oranges and replace it by calling a JS function from another file?
-
2You should write code in the language you need.SLaks– SLaks2016年06月27日 20:36:22 +00:00Commented Jun 27, 2016 at 20:36
-
1do you want to write java or javascript ?Sid– Sid2016年06月27日 20:36:52 +00:00Commented Jun 27, 2016 at 20:36
-
2Your question doesn't make a lot of sense. You're either running Java or you're running JavaScript (at least at this stage). Just write your program in one language.Mike Cluck– Mike Cluck2016年06月27日 20:37:00 +00:00Commented Jun 27, 2016 at 20:37
-
Don't be fooled by the names, Java and Javascript are two totally different languages. It is a quirk of marketing history that they sound similar. If you are new to programming, definitely you only want to learn one language at a time.user201891– user2018912016年06月27日 20:46:27 +00:00Commented Jun 27, 2016 at 20:46
-
Oh, but to answer your question "Is there a way to take the bit that says Oranges and replace it by calling a JS function from another file?" the answer is yes, but this is an incredibly advanced technique for a beginning programmer, as most programming languages do not interoperate easily.user201891– user2018912016年06月27日 20:51:29 +00:00Commented Jun 27, 2016 at 20:51
2 Answers 2
Java and javascript are two completely different things. Java is a full programming language while Javascript is used to make websites dynamic , so it works inside a webbrowser. You should figure what you want and make a choice.
2 Comments
As others said, you need to figure out what you want.
Nevertheless, it is possible to run Javascript in java. Check javax.script package and check the docs: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#evalfile