[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I'm brand new to programming, and I wanted to make a simple
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 19
Thread images: 3
File: javascript.png (2 KB, 225x225) Image search: [Google]
javascript.png
2 KB, 225x225
I'm brand new to programming, and I wanted to make a simple JavaScript program to add two numbers that were entered into the prompt. When I run it, it just combines the digits and doesn't add them. Can anyone tell me what I'm doing wrong?

var a = prompt("First Number?")

var b = prompt("Second Number?")

function add () {
add = a + b
alert(add)
}
>>
try replacing
add = a + b

with
parseFloat(a) + parseFloat(b)


JS is weird with how it handles types, apparently it's assuming a and b are strings so it's interpreting the '+' operator as concatenation rather than addition.
>>
>>54679000
Oh and the second piece of code should actually be
add = parseFloat(a) + parseFloat(b)
>>
oh no, not this imperative bullshit again! I thought we should be doing functional reactive programming in this day and age.


var a = prompt("First Number?")
var b = prompt("Second Number?")

var num1 = Rx.Observable.just(parseFloat(a));
var num2 = Rx.Observable.just(parseFloat(b));

addedNumber = Rx.Observable.combineLatest(num1, num2, (left, right)=>{return left+right})
addedNumber.subscribe((val)=>{alert(val)});

>>
Please, for the love of your sanity, don't learn javascript. Ever.

It's not easy, nor fun to work with.
>>
>>54679144
>javascript
>not easy
there are aspects that are tricky, but if js is "not easy" for you, you shouldn't be in the business at all
>>
>>54679131
Jesus Christ! All that to add 2 and 3
>>
>>54679151
not the guy you responded to, but i'm inclined to disagree with you -- while vanilla javascript isn't hard, staying up-to-date on the currently trendy frameworks/libraries/supplemental whatevers is certainly annoying as hell, especially in a business environment.
>>
>>54679151
*not easy to form a script that works well with all browsers™
>>
>>54679180
well, it's a pretty silly thing for the problem scenario, but would be pretty neat if you wanted add more functionality...

You'll love it if you need to add more complex functionality because the functional nature of it makes it simpler, if not easier.

replace one of the numbers with
Rx.Observable.range(0,10);

and you'll automatically get 10 alerts with all the additions.
>>
>>54679189
it's honestly not that hard to decide on a framework/library and stick with it. the danger is in constantly eyeing the landscape looking for another totally different way of organizing and doing things and talking about rewriting all your shit to go from one setup to another.

if you're just doing something like the MEAN stack, then you're fine. or go with react. whichever. but if you read hackernews you get the sense that everyone's writing react one week and then angular 2 the next, and then back to react and then meteor for a day and on and on. if they ARE doing that, then they're wasting precious man-hours.
>>
>>54679274
i understand what you're saying and i agree with it, but i think the problem really occurs when you're in a business environment where you don't exactly get to decide on what's being used.
>>
>>54679354
true, but my experience in industry is that teams will choose something and stick with it, so unless you're bouncing from company to company you shouldn't need to worry about following every breeze/trend.

maybe it's because i remember when there weren't clear winners in the web dev world; there was php (and the zend framework KIND of), then ruby on rails seemed to gain popularity but django insisted on trying to be relevant, and flask appealed to some people.

these days most startups at least are on JS. the differences between frameworks is closer to different dialects of the same (natural) language, rather than entirely different languages.
>>
File: 1460501672602.png (8 KB, 420x420) Image search: [Google]
1460501672602.png
8 KB, 420x420
>>54678966

()((a, b) => a + b));

done :^_
>>
>>54679354
>tfw my company just sticks with React/Knockout because backend is Django which does almost literally everything else
>>
File: 1460439876848.jpg (45 KB, 494x386) Image search: [Google]
1460439876848.jpg
45 KB, 494x386
>>54678966
Everyone above this post has been trolled by a rubybro with an anti-js agenda. Next up: == vs ===
>>
>>54679403
i'm somewhat new to to programming in a business environment, so that might have something to do with my frustration. hopefully my team sticks with the current stuff.
>>
>>54679574
if your company is jumping to a new framework they owe it to you to explain why they're doing it. if they jump a second time (landing on a third framework, or landing back on the first one), i would bring my CV up to date and start looking at job openings at other places.

it's great to be on the cutting edge, but doing it for the sake of being new and edgy is not just dangerous - it's a huge huge huge waste of your time. and more than the cost of servers and whatnot, developers' time is so valuable as to almost be sacred.
>>
>>54679632
haven't been with it long enough to know if they're gonna hop around between things, to be honest. i feel like i need to stay with them regardless of what happens, since my credentials are not exactly stellar just yet, and the experience is gold to me.
Thread replies: 19
Thread images: 3

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.