generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: JS problem

Previous Thread :: Next Thread 
TheBenSquare is not online. TheBenSquare
Joined: 13 Dec 2009
Total Posts: 13604
10 Oct 2015 01:03 PM
I coded this but for some reason, it gave me an error.

var TypeOfMath = prompt("What type of math would you like to perform?")

var AddNum = function(num1,num2) {
return num1 + num2;
};

var MultiplyNum = function(num1,num2) {
return num1 * num2;
};

var DivideNum = function(num1,num2)
return num1 / num2;
};

var SubtractNum = function(num1,num2)
return num1 - num2;
};





// Types of Math

if (TypeOfMath == "Add") {
var firstt = prompt("Please type in the first number.")
var secondd = prompt("Please type in the second number.")
var results = AddNum(firstt,secondd)
console.log(results)
}

else if (TypeOfMath == "Multiply") {
var firs = prompt("Please type in the first number.")
var secon = prompt("Please type in the second number.")
var multresults = MultiplyNum(firs,secon)
console.log(multresults)
}

else if (TypeOfMath == "Divide") {
var fir = prompt("Please type in the first number.")
var seco = prompt("Please type in the number you'd like to divide by.")
var divresults = DivideNum(fir,seco)
console.log(divresults)
}

else if (TypeOfMath == "Subtract") {
var fi = prompt("Please type in the first number.")
var se = prompt("Please type in the number you'd like to subtract from the first number.")
var subresults = SubtractNum(fi,se)
console.log(subresults)
}

else {
alert("You did not enter a valid command.")
}

The error was: Uncaught SyntaxError: Unexpected token return(…) VM186:13

I'm not sure why. Help?
Report Abuse
bigme2 is not online. bigme2
Joined: 20 Sep 2013
Total Posts: 404
10 Oct 2015 01:03 PM
This ain't for JavaScript dude
Report Abuse
TheBenSquare is not online. TheBenSquare
Joined: 13 Dec 2009
Total Posts: 13604
10 Oct 2015 01:07 PM
"This is the place for discussion about scripting."

JavaScript is a scripting language (although it cannot be used on ROBLOX server-side) so yeah.
Report Abuse
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
10 Oct 2015 01:09 PM
I'm sure there's some political definitions of "scripting" and "programming" that would diverge from one another, but in general: you can ask whatever PROGRAMMING questions you want.
Report Abuse
morash is not online. morash
Joined: 22 May 2010
Total Posts: 5834
10 Oct 2015 01:37 PM
Probably isn't the problem, but you forgot to convert the input to numbers.
Report Abuse
TheBenSquare is not online. TheBenSquare
Joined: 13 Dec 2009
Total Posts: 13604
10 Oct 2015 09:56 PM
I don't think that's why, I used some similar code for CodeAcademy and it worked there without converting.
Report Abuse
R0WE is not online. R0WE
Joined: 10 Mar 2013
Total Posts: 1807
10 Oct 2015 09:57 PM
I would recommend going to codeacademy. it teaches kids how to javascript
Report Abuse
morash is not online. morash
Joined: 22 May 2010
Total Posts: 5834
10 Oct 2015 09:59 PM
Oh, you forgot the open bracket with your divide function.
Report Abuse
Juddily is not online. Juddily
Joined: 24 Aug 2008
Total Posts: 4243
10 Oct 2015 09:59 PM
string values with only numerical characters can still be used in numerical operations

i.e. console.log("10"-5) would print '5'
Report Abuse
Weirdraidercs35 is not online. Weirdraidercs35
Joined: 14 May 2015
Total Posts: 2275
10 Oct 2015 09:59 PM
Khan academy also teaches JS.
Report Abuse
morash is not online. morash
Joined: 22 May 2010
Total Posts: 5834
10 Oct 2015 09:59 PM
Ditto with your subtract at second glance.
Report Abuse
Juddily is not online. Juddily
Joined: 24 Aug 2008
Total Posts: 4243
10 Oct 2015 10:00 PM
@morash and the subtract one
Report Abuse
Juddily is not online. Juddily
Joined: 24 Aug 2008
Total Posts: 4243
10 Oct 2015 10:00 PM
nvm got ninja'd
Report Abuse
TheBenSquare is not online. TheBenSquare
Joined: 13 Dec 2009
Total Posts: 13604
11 Oct 2015 11:35 AM
Thanks, added the bracket that I missed and it's now working as intended.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image