@DanLaff here you can see how I have done it until now.
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>
```
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");
}
:cookie: 415 | @ezioda004 |http://www.freecodecamp.org/ezioda004
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.
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?
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);
makeAdder
looks right to me without the if
statement
:cookie: 557 | @kbaig |http://www.freecodecamp.org/kbaig
@DanLaff
Thanks Dan, Now I understood what you mean with your code example.
You mean something like this
https://codepen.io/nicolaimagnussen/pen/aEgrrB
I agree with you, this is much better and much cleaner in my opinion as well, thanks for showing me that!! ;)
nicolaimagnussen sends brownie points to @danlaff :sparkles: :thumbsup: :sparkles: