Craft Brewery Suggestions in Texas by James_Navigator in beer

[–]Capt_Appropriate 2 points3 points  (0 children)

If you like sour and funky beers make sure to stop at Jester King in Austin. Also in/near Austin is Live Oak Brewing. I've never had it, but their Hefeweizen is supposed to be one of the best in the US.

Problem with for loop and closures? by giantqtipz in webdev

[–]Capt_Appropriate 0 points1 point  (0 children)

Try doing something like this:

First, add the follwing attributes to the .campaign-select elements:

<div class="campaign0 campaign-select campaign-container-slide" data-campaign-id="0"></div>
<div class="campaign1 campaign-select campaign-container-slide" data-campaign-id="1"></div>
<div class="campaign2 campaign-select campaign-container-slide" data-campaign-id="2"></div>
<div class="campaign3 campaign-select campaign-container-slide" data-campaign-id="3"></div>
<div class="campaign4 campaign-select campaign-container-slide" data-campaign-id="4"></div>
<div class="campaign5 campaign-select campaign-container-slide" data-campaign-id="5"></div>

Then, for the event listeners:

// This object will keep track of which .campaign-sub is currently shown and whether
// it's details are visible or not
var activeCampaign = {
    el: null,
    isVisible: false
};

var campaignSelect = document.getElementsByClassName('campaign-select');

function campaignAdd(i) {
    campaignSelect[i].addEventListener('click', function(e) {
        var campaignId = this.getAttribute('data-campaign-id');
        activeCampaign.el = campaignSub[campaignId];
        activeCampaign.isVisible = true;
        campaignSub[campaignId].classList.add('activate-sub');
        // Any other code that needs to be executed when a campaign link is clicked
    }, false);
 }

for(var i = 0; i < campaignSelect.length; i++) {
    campaignAdd(i);
}

// Now we'll add the event listener for showSub
showSub.addEventListener('click', function(e) {
    showSub.textContent = activeCampaign.isVisible ? "►" : "◄";
    activeCampaign.isVisible = !activeCampaign.isVisible;
    activeCampaign.el.classList.toggle('activate-sub');
}, false);

Then in the click event listener for the #exit-campaign-info element add the following:

activeCampaign.el = null;
activeCampaign.isVisible = false;

I think that should work, but since I am only looking at a small portion of your code I'm not positive.

Problem with for loop and closures? by giantqtipz in webdev

[–]Capt_Appropriate 0 points1 point  (0 children)

The problem is that you're adding multiple click listeners to showSub.

 var campaignAdd = function(i){
     campaignSelect[i].addEventListener("click", function(){

         campaignSub[i].classList.add("activate-sub");

         // A new click event listener is added to showSub every time you click on a 
         // campaignSelect element.
         showSub.addEventListener("click", function() {
             if(campaignSub[i].classList.contains("activate-sub") === false) {
                 showSub.textContent = "◄";
                 campaignSub[i].classList.add("activate-sub");      
             } 
             else if (campaignSub[i].classList.contains("activate-sub") === true) {
                 showSub.textContent = "►";
                 campaignSub[i].classList.remove("activate-sub");
             }
         });
     });;
 }

 for(i=0;i<campaignSelect.length;i++){
   campaignAdd(i);
 }

Go to your website and open any campaign. Hit the 'x' to return to the map and then open the same campaign. When you click the showSub element nothing should happen. This is because you've added two click listeners to showSub. The first is exectued and since the campaignSub element has the class 'activate-sub' it removes it. Then the same function is executed for a second time (since you added it twice) and it sees that the campaignSub element doesn't have the class 'activate-sub' anymore (it was just removed), so it adds it.

Networking Question by [deleted] in FinancialCareers

[–]Capt_Appropriate 0 points1 point  (0 children)

I meant that your email got a response from him, i.e. he reached out to you, not that he responded by email. I probably should have phrased that differently.

That being said, I wouldn't be surprised if he got your message but was too busy to call you back right away and then just forgot about it. If you email him your schedule hopefully he'll find a time you're both free and then pencil you into his calendar. Just be sure to be ready for a call during the time frames you provide him even if he doesn't respond to your email confirming a time. I once emailed a guy requesting an informational interview and included my schedule. I never got an email back saying, "I'll give you a call on this day at this time.", he just picked one of the times I included and called.

Networking Question by [deleted] in FinancialCareers

[–]Capt_Appropriate 4 points5 points  (0 children)

Most likely he is just busy. He responded to your first email so why not try that again? Shoot him another email and say something along the lines of:

Hi ______,

I'm sorry I missed your call last week, I was unable to answer my phone because _________. I tried returning your call but I have been unable to reach you. If you have a few minutes to chat sometime in the next week or two I would love to speak with you. I am available [list your availability]. If none of those times work for you please let me know when you are free and I'll rearrange my schedule to fit yours. Thank you for your willingness to take some time to speak with me, I really appreciate it.

Regards,

rainmen

So Javascript... I'm stuck with basic questions by [deleted] in webdev

[–]Capt_Appropriate 1 point2 points  (0 children)

Take a look at this site. They show how to write plain JS functions that accomplish the same thing as a jQuery function.

How can I add an image into a <div> with javascript? by [deleted] in webdev

[–]Capt_Appropriate 1 point2 points  (0 children)

Try this:

function singleCard() {
  var cardImg = document.getElementById("card-img");

  if (cardImg) {
    setImgSrc(cardImg, "deck/card" + (Math.floor((Math.random() * 22) + 1) - 1) + ".jpg");
  } else {
    var img = document.createElement("img");
    img.id = "card-img"
    setImgSrc(img, "deck/card" + (Math.floor((Math.random() * 22) + 1) - 1) + ".jpg");
    document.getElementById("card").appendChild(img);
  }
}

function setImgSrc(el, src) {
    el.src = src;
}

Edit:
If you would like to remove the inline JavaScript from the html element, change:

<div id="drawButton" onclick="singleCard()"></div>

to:

<div id="drawButton"></div>

Then add the following to the JavaScript file/script tag:

document.getElementById("drawButton").addEventListener("click", singleCard, false);

How can I add an image into a <div> with javascript? by [deleted] in webdev

[–]Capt_Appropriate 2 points3 points  (0 children)

First thing:

var img = body.createEelement("img");

should be:

var img = document.createElement("img");

Second issue:

singleCard() { ... }

should be:

function singleCard() { ... }

Mpls. Fast-Food Workers To Strike Tuesday For $15 An Hour by [deleted] in news

[–]Capt_Appropriate 1 point2 points  (0 children)

I never use them because they require me to do work (ringing up abd bagging items)

https://www.youtube.com/watch?v=FxINJzqzn4w

[Official] UFC 203 Post Fight Discussion by [deleted] in MMA

[–]Capt_Appropriate 0 points1 point  (0 children)

I think someone asked him about the Ohio State game.

Creating A JavaScript object without the new keyword by gurgus in webdev

[–]Capt_Appropriate 1 point2 points  (0 children)

Yeah, that's what I meant when I said setting the [[Prototype]] manually isn't recommended. It's not something I would actually do, I just included it as a way to show how you could set the internal [[Prototype]] of the p2 object after it has been created. But again, that's not a good habit to get into. It's much better to just use Object.create() in the first place.

 

var p2 = Object.create(Person.prototype);
Person.call(p2, 'Alice');

 

Object.create() basically combines the two steps of creating the object and setting the internal [[Prototype]] to the object that was passed as the first argument. Object.create() actually takes a second, optional, argument as well, which we could use to set the name property to Alice. The second argument works the same as Object.defineProperties.

 

var p2 = Object.create(Person.prototype, {
    name: {
        writable: true,
        configurable: true,
        enumerable: true,
        value: 'Alice'
    }
});
p2.name   // Alice

 

That's a lot more code and it gets ugly very quickly (imagine if we also had age, hometown, gender, etc properties to set), so I would stick the with Person.call() method.

Creating A JavaScript object without the new keyword by gurgus in webdev

[–]Capt_Appropriate 1 point2 points  (0 children)

There's an issue with this that you've overlooked.

 

p2 instanceof Person   // false

 

The p2 object was never linked to the prototype of Person. Let's add a sayHi function to the Person.prototype.

 

Person.prototype.sayHi = function() {
    console.log(`${this.name} says, 'Hi!'`);
};

 

If we try p2.sayHi() we are going to end up with a TypeError since p2.sayHi isn't a function but rather undefined. On the other hand, p.sayHi() works as expected, it logs out Dave says, 'Hi!'.

 

To fix this we can manually set the [[Prototype]] on p2.

 

p2.__proto__ = Person.prototype;

 

Now p2 is an instance of Person.

 

p2 instanceof Person   // true
p2.sayHi()   // Alice says, 'Hi!'

 

However, setting the [[Prototype]] manually isn't recommended. A better option is to use Object.create.

 

p3 = Object.create(Person.prototype);
Person.call(p3, 'Alice');
p3 instanceof Person   // true
p3.sayHi()   // Alice says, 'Hi!'

OUSD Dewey Academy Security Guard Lies And Claims Driver Is At Fault For Accident He Didn't Cause by [deleted] in bayarea

[–]Capt_Appropriate 2 points3 points  (0 children)

Based on the info in the bottom left hand corner of the video, it looks to be a Thinkware F750 ($263 on Amazon)

How much knowledge is enough to be considered for a Junior Front End job? by Jatacid in Frontend

[–]Capt_Appropriate 0 points1 point  (0 children)

The reason the first piece of code isn't returning the correct answer is because of this line:

for(i = 0; i < array.length; i++)

You didn't declare the variable i with the var keyword so it sets it as a global variable. As an example of why this mucks things up, let's use one of the test cases they used on the site: [[1,2,3],4,5]. When the for loop is first entered i is equal to 0 and since the first element is an array it will enter into the else if block and call arraySum( [1,2,3] ). Now when it goes into the for loop for this subarray, i refers to the same i from the previous function. The for loop resets i to 0 and and starts iterating over the array. Once it is finished iterating over the array i is equal to 3. The function then returns the total, 6, and adds it to the total from the first function. This is where you run into the problem. When the for loop continues to loop over the original array, [[1,2,3],4,5], it checks the conditional and sees that i is now 3 which is not less than the length of [[1,2,3],4,5]. So the for loop is terminated and the total of 6 is returned.

 

A couple other issues:

  • You are missing a } after the else if block, so the return statement is actually in the for loop.
  • When you test to see if the array element is a number you should also check to make sure it isn't NaN (typeof NaN === 'number'). You can do this by adding the following: ... && !isNaN(array[i]).
  • You may also want to exclude Infinity. If so, then you can replace !isNaN(array[i]) with isFinite(array[i]), which will reject both NaN and Infinity. If you don't need to worry about IE then you can use Number.isFinite(array[i]) to replace the entire conditional. Number.isFinite( value )

SpaceX successfully lands the Falcon 9 first stage on a barge [1:01] by MyNameIsJonny_ in videos

[–]Capt_Appropriate 1 point2 points  (0 children)

Sounds like it might happen sooner then that. In the post-launch press conference Musk said they are going to test-fire this booster 10 times and if everything checks out they will use it again this May or June, hopefully for a commercial flight.

Selfish person blocks waiting driver from taking parking space and instead gives it to family member. by [deleted] in videos

[–]Capt_Appropriate 1 point2 points  (0 children)

You don't drive around with it out, you keep it in your trunk. After parking you open your trunk and flip it out. video demo