JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
Apr 15, 2015 00:34
thanks
Apr 15, 2015 00:34
ahhhhh, duh
Apr 15, 2015 00:32
right, so it has to be passed in as a string?
Apr 15, 2015 00:32
@mintsauce , but if I pass in 0, 0.25, 0.75, or 1, it they all return the correct string
Apr 15, 2015 00:31
@Min
Apr 15, 2015 00:30
var getInteractionType = function (percentWatched) {
return {
'0': '100',
'0.25': '101',
'0.50': '101',
'0.75': '101',
'1': '103'
}[percentWatched];
};

console.log(getInteractionType(0));
console.log(getInteractionType(0.25));
console.log(getInteractionType(0.50));
console.log(getInteractionType(0.75));
console.log(getInteractionType(1));
Apr 15, 2015 00:30
Any idea why 0.50 is returning undefined?
Feb 25, 2015 18:59
@ssube, thanks
Feb 25, 2015 18:56
@ssube, so is it a best practice to use return?
Feb 25, 2015 18:52
@BenjaminGruenbaum, could you explain? I'm still learning...
Feb 25, 2015 18:51
@ssube, well all I want to do is update the the element with an attribute, so i guess that means i am returning an updated element
Feb 25, 2015 18:48
function setAttributesOnElement(element, name, value){
element.attr(name, value);
}
Feb 25, 2015 18:48
hey all, is it better to include return in a function than to not?
Feb 24, 2015 23:32
is going to have to select
Feb 24, 2015 23:32
not sure how many @jack
Feb 24, 2015 23:31
right maybe the title was misleading. all I'm trying to convey is that var $foo = $('#foo') is equal to var blah = { $foo: $('#foo') }, no?
Feb 24, 2015 23:26
I'd say caching a selector via a var vs. an object is the same thing
Feb 24, 2015 23:24
@Jack, take a look at this article. The guy is talking about storing selectors in an object. eamann.com/tech/selector-caching-jquery
Feb 24, 2015 23:12
@Jack, yeah, I don't see why you couldn't. To access them you'd just have to do elem.$doc though...
Sep 12, 2013 23:58
thanks, i just read about the nodelist.
Sep 12, 2013 23:50
I'm trying to get the inner HTML of an h1 using this: document.getElementsByTagName('h1').innerHtml but it's returning undefined. Possible?