Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Dan Lafferty
@DanLaff
@nicolaimagnussen document.ready is deprecated in jQuery 3, but no, you don't always need it. If you have code that needs to wait for scripts to download first, for example, it can be necessary.
Rarely necessary though
I think if you're trying to alert the value of the button clicked, you can just give each button a class name like "digit" and do:
$('.digit').on('click', function() {
  alert($(this).val())
});
Dan Lafferty
@DanLaff
@KUBIX90 In HTML, the value of your ID attribute needs to be unique. Change id='status' in your JS to class='status' and modify your JS to use .status instead of #status
That will get the text showing up, but you'll still need to work out why it says "offline" for everyone
Anders Nicolai Magnussen
@andersnicolaimagnussen

so this would actually be considered better practice than having the btn on click on the HTML elements itself, that is intereseting.
And you are saying one of the reasons is because you want to have organised code, and keep the javascript /jquery seperated from the html.. .

Do you know why I cant access the function called tall from the click function here.

If you want an have time, I can share the code I had before with jquery and onclick, so maybe you can look over it and tell me the best way to implement what I want with Jquery?

Everything was working fine before, but the teacher has a test in python that checks for jquery and not just javascript as I have understood it.

Dan Lafferty
@DanLaff
@nicolaimagnussen Maybe you're trying to do this?
function functionOne() {

  function functionA() {
    // do something
  }

  function functionB() {
    // do something else
  }

  functionA(); // this will work fine
}

functionA(); // doesn't run because you can't call a function inside another function out here
From a quick look at your code - you may want to review Immediately Invoked Function Expressions (IIFE) and Function Scope in JavaScript. It's the same concept in jQuery, just slightly different syntax.
Mark Kubik
@KUBIX90
@DanLaff Thanks, got that bit working at least, my border shadow seems to work fine in showing the channels as offline/online, will have a look as to why its showing the same text throughout
CamperBot
@camperbot
kubix90 sends brownie points to @danlaff :sparkles: :thumbsup: :sparkles:
api offline
Alan M.
@Am3ra
Hey all,
can anyone help me?
cant figure out why the regex maybe isnt working, or the filter function
Anders Nicolai Magnussen
@andersnicolaimagnussen

@DanLaff here you can see how I have done it until now.

https://codepen.io/nicolaimagnussen/pen/aEgrrB

I can see the calculator is not perfect, but I am just wondering how I can start changing the stuff to jquery, and change up the click events on the buttons

the code pen you sent me makes sense, using a for loop to iterate trough the buttons. That was smart.

But what if you would like to send in a value, for example if the user click on 7, like the way I have done it here.

        <button onclick="tall(7)" value="7" class="btn btn-primary" id="seven">7</button>

```

Dan Lafferty
@DanLaff
@nicolaimagnussen It's a good start. You are using jQuery. You don't need to use jQuery function syntax too, I would guess, but I haven't seen what your teacher is asking.
If you can alert the value "7", you can use .html() or .text() to update an element's content with that value
You may want to keep things in english if you can - brukerTall = userButton :)
Anders Nicolai Magnussen
@andersnicolaimagnussen
Okey, I am really new to the javascript world and the Jquery world. I don'r really know if he is directly testing if we are using jquery instead of javascript, but I would think so.
Yes, you can try the calculator, that works, but I am wondering how I would do it with a click function instead.
I would then need a lot of click functions, and that would look messy in my opinion. But it would look nice with a for loop as in your example though.
But how could I then pass in the values like, 5, 6, 7 and so on depending on which button the user clicks on. Thanks for your time @DanLaff :)
CamperBot
@camperbot
nicolaimagnussen sends brownie points to @danlaff :sparkles: :thumbsup: :sparkles:
api offline
Dan Lafferty
@DanLaff
It will make it easier to get help here when your code gets more complicated
Anders Nicolai Magnussen
@andersnicolaimagnussen
Yes, good tip. I will change that right away
Aditya
@ezioda004
@KUBIX90 This should work
if(val.stream === null){
                    $("#" + username).css("box-shadow", "5px 0px 10px red");
                    $("#" + username + ">p").text("Offline")
                                .css("color","red");
                } else {$("#" + username).css("box-shadow", "5px 0px 10px green");
                        $("#" + username + ">p").text("Online")
                                    .css("color","green");
                        }
Easier to select this way without modifying any other parts.
Mark Kubik
@KUBIX90
@ezioda004 Thanks that works perfectly, but I'm not 100% understanding why?
CamperBot
@camperbot
kubix90 sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 415 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Mark Kubik
@KUBIX90
@ezioda004 Why the ">p"?
Dan Lafferty
@DanLaff
@KUBIX90 It selects all the <p> elements in the #username div https://www.w3schools.com/cssref/css_selectors.asp
Could be troublesome if you add more <p> elements - but goes to show, there are lots of ways to select an element :)
Aditya
@ezioda004
@KUBIX90 With your previous code, you were overwriting the #status since it only selects one. The >p selects child of $("#" + username).
Mark Kubik
@KUBIX90
@DanLaff @ezioda004 Ahh I see thanks for the help both, the fact it was being used in a jQuery context threw me off, I've only ever used it in my CSS file.
CamperBot
@camperbot
kubix90 sends brownie points to @danlaff and @ezioda004 :sparkles: :thumbsup: :sparkles:
api offline
api offline
Kaleb.sh
@porowns

Hi, got a somewhat weird question.

I have a button with and onclick effect, and I'm trying to build up the url of the onclick based on previous button presses, but not really sure how.

Example

<button class=onclick="location.href='https://test.com/{{VARIABLE}}'">
</button>

I'd like to set {{VARIABLE}} using javascript (from a previous onclick()), but not exactly sure how I'd do that. I was thinking about putting like a div and then replacing the value using javascript, but I feel that the '' will negate the div.

Anders Nicolai Magnussen
@andersnicolaimagnussen

Okey, I have fixed a little bit more here now.

https://codepen.io/nicolaimagnussen/pen/aEgrrB

So how can I change all this code to click functions instead?

Daniel Feldman
@Feldbot
I'm having some troubles with this algorithm challenge. I'm getting 3/5 test cases to evaluate okay, but the ones that say, for example, addTogether(2)(3) should return 5. aren't passing. I'm guessing that they mean the 3 is the function factory argument that is passed in in the code, but I'm not sure. You can't call a function with two arguments like they are suggesting that I know of. I'm just not quite getting why these don't pass. Any thoughts?

function addTogether(num1, num2) {

  var add3 = makeAdder([3]);
  var sum;
  var number = true;

  // Function to test if arguments are numbers
  function numTest(args) {
    for (var prop in args) {
      console.log(args[prop]);
      if (typeof args[prop] !== 'number' || Array.isArray(args)) {
        number = false;
      }
    }    
  }

  // 1 argument case
  if (arguments.length === 1) {
    numTest(arguments);
    if (number === false) {
      return undefined;
    } 
    return (add3(2));
  }

  // 2 arguments case
  if (arguments.length > 1) {
    numTest(arguments);
    if (number === false) {
      return undefined;
    } 
    sum = num1 + num2;
    return sum;  
  }

  // makeAdder function
  function makeAdder(x) {
    return function(y) {
      numTest(x);
      if (number === false) {
        return undefined;
      }

      return x + y;
    };
  }
}

addTogether(2);
Kaz Baig
@kbaig
@Feldbot You just need to simplify it so that you have a case for arguments.length being either 1 or 2
if 1, return a function. Your makeAdder looks right to me without the if statement
If 2, return sum of the two args
You have all the components here already
Darren
@DarrenfJ

@kbaig hey buddy thanks for the larfs ;)

But we gotta have semantic markup :clap:

CamperBot
@camperbot
darrenfj sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 557 | @kbaig |http://www.freecodecamp.org/kbaig