|
| 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
|
  |
| Joined: 20 Sep 2013 |
| Total Posts: 404 |
|
|
| 10 Oct 2015 01:03 PM |
| This ain't for JavaScript dude |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 10 Oct 2015 09:59 PM |
| Khan academy also teaches JS. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 10 Oct 2015 09:59 PM |
| Ditto with your subtract at second glance. |
|
|
| Report Abuse |
|
|
Juddily
|
  |
| Joined: 24 Aug 2008 |
| Total Posts: 4243 |
|
|
| 10 Oct 2015 10:00 PM |
| @morash and the subtract one |
|
|
| Report Abuse |
|
|
Juddily
|
  |
| Joined: 24 Aug 2008 |
| Total Posts: 4243 |
|
| |
|
|
| 11 Oct 2015 11:35 AM |
| Thanks, added the bracket that I missed and it's now working as intended. |
|
|
| Report Abuse |
|
|