Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Javascript triangle project

Name: Conserned Citizen 2012-10-27 22:00

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 + ".");

Name: Anonymous 2012-10-27 22:08

>>1
side1 + side2 <= side3 || side2 + side1 <= side3
This is my favorite. Maybe computers aren't for you.

Name: Conserned Citizen 2012-10-27 22:10

No, I knew that it doesn't make a difference but I thought I'd try to see if that fixed it for some reason. Obviously doesn't do shit.

Name: Anonymous 2012-10-27 22:28

prompt("Input the length of side A(Not the longest).")
prompt("Input the length of side B(Not the longest).")
prompt("Input the length of side C(Longest side).")
Why would you make the user deal with bullshit like this? This is bad behavior. What if multiple sides are the longest?

side1 + side2 <= side3 || side2 + side1 <= side3
...

triangle.real = "not real"
Bools?

Name: c 2012-10-27 22:34

>>4

Because I'm just developing this as a way to test my skills, I'm . I'm just trying to get better at this.

Yeah I know. In some weird logic from me staring at it too long I thought that would do something for whatever odd reason.

And I'm not using Bools because I'm printing that (see last line)

Name: Anonymous 2012-10-27 22:38

I don't see any code, but:
if (side1 + side2 <= side3 || side2 + side1 <= side3)
may be one of the funniest statements I have ever seen.
Do you know how addition works?

Name: Anonymous 2012-10-27 22:44

And I'm not using Bools because I'm printing that (see last line)
10: triangle.real = false;
13: triangle.real = true;
18: alert("The triangle is " + (triangle.real?"real":"not real") + ".");

Name: Anonymous 2012-10-27 23:06

>>2-7 (minus >>3,5)
You're dealing with a Javashit developer, this was bound to happen.

Still, the side1 + side2 <= side3 || side2 + side1 <= side3 was too fucking much for my sides. Leah quality.

Name: Le JS Culver 2012-10-27 23:14

i wonder if there's any way of doing this mathematically???

Name: Anonymous 2012-10-27 23:36

>>9
everything can be solved with math

Name: Anonymous 2012-10-28 0:00

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.

Name: Anonymous 2012-10-28 0:06

function is_real_triange(sides) {
  return sides.length == 3 && sides.sort() && sides[2] > sides[0] + sides[1];
}

alert('The triangle is ' +
      is_real_triangle(JSON.parse(prompt('Enter the lengths as a JSON array.'))) ?
        'real.' :
        'not real.');

Name: Anonymous 2012-10-28 12:13

return my anus

Name: Anonymous 2012-10-28 12:13

2012
not using coffeescript

-> anus

Name: Anonymous 2012-10-28 12:14

>>10--11
/polecat kegabs/

Name: Anonymous 2012-11-13 17:23

wat wat in teh bump

Name: Anonymous 2012-11-13 20:01

>>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: Anonymous 2012-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)."));

Name: Anonymous 2012-11-13 20:31

>>17
:)
fuck off, fagshit

Name: Anonymous 2012-11-13 20:34

>>17
The wonders of dynamic typing!

Name: Anonymous 2012-11-13 20:47

>>20
another innovation brought to you by javascript

Name: Anonymous 2012-11-13 20:57

>>21
i want utmost honesty, javascript guy.

why do you do this? even people who use js admit it has some bad things.

i don't know what are you trying to achieve by trolling the 3 people who lurk /prog/ regularly.

please tell me why you do this, i really want to know.

thanks.

PD: please, please respond, you always ignore everything that's said to you

Name: Anonymous 2012-11-13 22:33

bumping so javascript guy can see my post

Name: Anonymous 2012-11-14 6:29

still waiting, javascript guy

Name: Anonymous 2012-11-22 16:28

wait my anus

Name: Anonymous 2012-11-22 16:50

i waited for your anus but got nothing of interest

Name: Anonymous 2012-11-22 19:03

>>26
I would answer, but I am just a javascript guy, not the javascript guy.

Name: Anonymous 2012-11-22 19:39

>>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

Name: Anonymous 2012-11-22 20:37

var triangle = new Object();
Typical JavaScript programmer, using an object and a property instead of printing a fucking string using a conditional statement.

Name: Anonymous 2012-11-23 0:34

>>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.

Name: Anonymous 2012-11-23 12:35

SHIT LOL. JAVASHIT MY ANUS

Name: Anonymous 2012-11-23 12:51

>>30
they will all be fixed in ES6
You haven't seen the ES6 I've seen.

Name: Anonymous 2012-11-23 13:58

>>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.

Name: Anonymous 2012-11-23 14:45

>>33
Naruto will get good soon, I promise.

Name: Anonymous 2012-11-23 14:46

>>34
Just like Javascript!

Name: Anonymous 2012-11-23 16:09

>>33
Programming languages are not cartoons, so this analogy fails.

Name: Anonymous 2012-11-23 16:13

>>36
Javascript is too shitty to be considered an actual programming language.

Name: Anonymous 2012-11-23 17:56

Javascript triangle project ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

Name: Anonymous 2012-11-23 19:32

>>38
Triangles are out. Quads are where it's at bro

Name: Anonymous 2012-11-23 21:56

>>38
These corner rounders consider anything a project nowadays.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List