Off Topic > Off Topic
Programming Megathread
Foxscotch:
--- Quote from: Becquerel on January 04, 2016, 01:45:15 AM ---Anyone here extremely experience with Javascript?
If so, I got a question for you that Ive had since I started learning the language.
You know how to create an object using a constructor is
--- Code: ---var object = new Object();
--- End code ---
?
I was wondering if its possible to add arguments into the parenthesis of the object constructor. Thanks!
--- End quote ---
that just creates an "Object" object
Object is the class from which more specialized types inherit. I think pretty much all languages with object-oriented features have something like this. for example, Python's object or Java's java.lang.Object. and usually in these cases you don't have to explicitly say that the class inherits from that class, it's just assumed
these root classes define some methods and maybe properties that all classes should have, but there's not often a reason to use them yourself. you might never have any reason to type what you have in that code block there
and to answer your actual question, it can take arguments
> var o = new Object();
> o
Object {}
> var o = new Object(12);
> o
Number {[[PrimitiveValue]]: 12}
> var o = new Object(true);
> o
Boolean {[[PrimitiveValue]]: true}
but under normal circumstances you'd be better off just using primitives
Becquerel:
thanks nightfox
Ipquarx:
--- Quote from: lolguy1553 on December 31, 2015, 03:14:08 PM ---And Malbolge.
It's impossible.
--- End quote ---
someone actually made 99 bottles of beer on the wall in malbolge
that's no easy feat
Alyx Vance:
Ah good this is still alive. I have a question regarding python.
a = input("Enter tax rate ")
b = input("Enter amount paid ")
c = input("Enter how many times paid ")
d = a*b
print(d)
I write this but when it goes to multiply it just says
--- Quote ---Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
d = a*b
TypeError: can't multiply sequence by non-int of type 'str'
--- End quote ---
any idea how to fix this?
Pecon:
--- Quote from: Alyx Vance on January 15, 2016, 01:10:56 PM ---Ah good this is still alive. I have a question regarding python.
a = input("Enter tax rate ")
b = input("Enter amount paid ")
c = input("Enter how many times paid ")
d = a*b
print(d)
I write this but when it goes to multiply it just says any idea how to fix this?
--- End quote ---
Try
a = input("Enter tax rate ")
b = input("Enter amount paid ")
c = input("Enter how many times paid ")
a = int(a)
b = int(b)
c = int(c)
d = a*b
print(d)
(Disclaimer: I don't know python, I just did a quick search on how to typecast in it)