So I'm trying to write a JS that takes the sides of triangles and determines if they're real or not. It keeps fucking up though and I have NO idea why.
Code:
//Gather input
var side1 = prompt("Input the length of side A(Not the longest).");
var side2 = prompt("Input the length of side B(Not the longest).");
var side3 = prompt("Input the length of side C(Longest side).");
//Create triangle object
var triangle = new Object();
//Find out if the triangle is real
real = function() {
if (side1 + side2 <= side3 || side2 + side1 <= side3) {
triangle.real = "not real";
}
else{
triangle.real = "real";
}
};
//Call functions and display answer
real();
alert("The triangle is " + triangle.real + ".");
I'd just like to interject for a moment. What you’re referring to as JavaScript, is in fact, V8/JavaScript, or as I’ve recently taken to calling it, V8 plus JavaScript. JavaScript is not an operating system unto itself, but rather another free component of a fully functioning V8 system made useful by the V8 corelibs, shell utilities and vital system components comprising a full OS as defined by ECMA.
Many computer users run a modified version of the V8 system every day, without realizing it. Through a peculiar turn of events, the version of V8 which is widely used today is often called JavaScript, and many of its users are not aware that it is basically the V8 system, developed by the V8 Project. There really is a JavaScript, and these people are using it, but it is just a part of the system they use.
JavaScript is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. JavaScript is normally used in combination with the V8 operating system: the whole system is basically V8 with JavaScript added, or V8/JavaScript. All the so-called JavaScript distributions are really distributions of V8/JavaScript.
>>1
Hi OP, the problem is that prompt() returns a string, but your numerical calculations (side1 + side2 <= side3 and so on) require numbers.
To convert the user input to numbers, we need JavaScript's built-in parseFloat function. Try wrapping your prompts with parseFloats, like so:
var side1 = parseFloat(prompt("Input the length of side A(Not the longest)."));
var side2 = parseFloat(prompt("Input the length of side B(Not the longest).");
var side3 = parseFloat(prompt("Input the length of side C(Longest side)."));
Hope that helps! :)
Name:
Anonymous2012-11-13 20:02
>>17
Whoops, I forgot a ) on the second line. It should be: var side2 = parseFloat(prompt("Input the length of side B(Not the longest)."));
>>27
if you're a javascript guy, you are the javascript guy.
i don't know what kind of retarded shit have you smoked lately, but there's no way someone would troll the shit out of /prog/ for an indefinite time with a really bad language
Ahmed is doing the same thing, except ``Symta'' is better than javascript
var triangle = new Object();
Typical JavaScript programmer, using an object and a property instead of printing a fucking string using a conditional statement.
>>28
I admit JavaScript has some problems (although they will all be fixed in ES6), and I admit it did not invent dynamic typing (although it did perfect it). Hope that satisfies you.
>>30
You sound like one of those stubborn kids when they go ``wah my favorite cartoon has some bad points but i'm sure they will fix it next season XD'' and it never improves, it only gets worse and worse by adding shit on top of more shit.