$("body").on("click", function (){
$(this).css("background-color", "#000ff00");
});
let flag = false;
$("body").on("click", function (){
if(!flag){
$(this).css("background-color", "#000ff00");
flag = true;
}else
$(this).css("background-color", "#someothercolor");
flag = false;
});
trommelochse sends brownie points to @orangekulture :sparkles: :thumbsup: :sparkles:
:cookie: 451 | @orangekulture |http://www.freecodecamp.com/orangekulture
rafaelmonroy sends brownie points to @orangekulture :sparkles: :thumbsup: :sparkles:
:cookie: 452 | @orangekulture |http://www.freecodecamp.com/orangekulture
rafaelmonroy sends brownie points to @orangekulture :sparkles: :thumbsup: :sparkles:
:warning: rafaelmonroy already gave orangekulture points
Math.floor(Math.rand() * 255)
$("button").removeclass("fa-5x");
$("button").addclass("fa-3x");
$('.yourClass').removeClass
$('.yourClass').removeclass
addclass
var fruit = 'apple';
console.log(fruiT) // => undefined
TypeError: $(...).removeclass is not a function
function countCharacter(str, char) {
let reg = new RegExp(char, "gi");
if (reg === undefined || "0") {
return (0);
} else {
return str.match(reg).length;
}
}
ismailhozain sends brownie points to @trommelochse :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @trommelochse |http://www.freecodecamp.com/trommelochse
if (str.match(reg)) {
// do stuff
}
else {return null}
0 !== null !== false !== undefined
0 == null == false == undefined
rafaelmonroy sends brownie points to @just1witness :sparkles: :thumbsup: :sparkles:
:cookie: 303 | @just1witness |http://www.freecodecamp.com/just1witness
body {
transition: background-color 1250ms;
}
transition
in the original state
a {
color: red;
transition: color 1s;
}
a:hover {
color: blue;
}
thuannguyen13 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 535 | @longnt80 |http://www.freecodecamp.com/longnt80
a {
color: red;
font-size: 1rem;
transition: all 1s;
transition-property: color,font-size;
}
a:hover {
color: blue;
font-size: 1.2rem;
}
transition: display 1s; ?
var array = [1, 12, 21, 2];
// Only change code below this line.
array.sort(function(a,b){
return b-a;
});
why is largest to smallest and not minus...?
rafaelmonroy sends brownie points to @trommelochse :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @trommelochse |http://www.freecodecamp.com/trommelochse
orangekulture sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3247 | @khaduch |http://www.freecodecamp.com/khaduch
orangekulture sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 536 | @longnt80 |http://www.freecodecamp.com/longnt80
orangekulture sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: orangekulture already gave khaduch points
raka26 sends brownie points to @orangekulture :sparkles: :thumbsup: :sparkles:
:cookie: 454 | @orangekulture |http://www.freecodecamp.com/orangekulture
quick question, why does this code work
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
but not this one
var x = $("#demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
all i did was change the way I grabbed the elememt, JQuery is activated on my pen
gothamknight sends brownie points to @rafaelmonroy :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @rafaelmonroy |http://www.freecodecamp.com/rafaelmonroy
@Masd925 @gothamknight i switched it to jQuery
var coordinates = $('#demo');
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
$('#coordinates').html("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
$('#coordinates').html("Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude)
}
the code still wont run :/ but when i change my view to debug, it works? why is that ?
getLocation
?
getLocation();
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
$(document).ready(function(){...})
?
document.addEventListener("DOMContentLoaded",function(){...});
or window.addEventListener("load",function(){...});
rafaelmonroy sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 407 | @gothamknight |http://www.freecodecamp.com/gothamknight
function filterer() {
console.log("i got called");
var newArr1 = argArr.filter(function() {
return newArr1;
});
console.log(newArr1);
}
function destroyer(arr) {
console.log(arguments.length); // logs destroyer function's arguments' length => 3
var argArr = Array.prototype.slice.call(arguments); // one way of converting arguments into real array
console.log(argArr); // logs new argument array
var filteredArr = argArr.filter(function(filter){
return ;
});
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
// var args = [].slice.call(arguments); // another way of converting arguments into real array
arr.filter(yourFilteringFunction);
yourFilteringFunction
. That function should return true
or false
function isBigEnough(value) {
return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]
col-md-4
and col-xs-6
both in the same divhttps://codepen.io/hemakshis/pen/xLQRJB
[1, 2, 3, 1, 2, 3], 2, 3
hemakshis sends brownie points to @garrusnapp :sparkles: :thumbsup: :sparkles:
:cookie: 841 | @garrusnapp |http://www.freecodecamp.com/garrusnapp
display: inline-flex;
flex-wrap: wrap;
justify-content: space-evenly;
<div class="container"> <div> project 1 </div> <div> project 2 </div> .... </div>
hemakshis sends brownie points to @garrusnapp :sparkles: :thumbsup: :sparkles:
:warning: hemakshis already gave garrusnapp points
function destroyer(x) {
//for now x is like [1,2,3,4,5],2,1.
// unpack it here so you have variable with only [1,2,3,4,5]
//also I created a global variable with the rest of the argument: 2,3
//[1,2,3,4,5].filter(callback)
}
function callback(valueSentByFilter) {
//indexOf here using the global variable from above to decide whether return true or not
}
feldbot sends brownie points to @garrusnapp :sparkles: :thumbsup: :sparkles:
:cookie: 842 | @garrusnapp |http://www.freecodecamp.com/garrusnapp
The answer might be correct but I didn't understand the solution and what to do to fix it.
var destroyedArr = [];
function callback(valueSentByFilter) {
if (initialArr.indexOf(testArgs) === -1) {
destroyedArr.push(); // ??? push what?
// console.log(testArgs);
// console.log(destroyedArr);
}
}
function destroyer(arr) {
// console.log(arguments.length); // logs destroyer function's arguments' length => 3
var argArr = Array.prototype.slice.call(arguments); // one way of converting arguments into real array
// console.log(argArr); // logs new argument array
initialArr = argArr[0];
testArgs = argArr.splice(1);
// console.log(initialArr);
// console.log(testArgs);
initialArr.filter(callback);
console.log(destroyedArr);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
valueSentByFilter
is the thing you use against indexOf
[stuff you don't want].indexOf(value sent by filter) == -1
.filter
that will return elements that passed the test (those elements that taken by callback function , caused it to return true)
return array.filter(callback)
function callback(valueSentByFilter) {
if (testArgs.indexOf(valueSentByFilter) === -1) { // syntax: arr.indexOf(searchElement[, fromIndex])
// -1 means it is NOT found in array
// [2, 3] are searched for matches iteratively by [1, 2, 3, 5, 1, 2, 3]
// since 1, 5, 1 are true they are then filtered in the destroyer function as the callback values
return true;
}
}
feldbot sends brownie points to @garrusnapp :sparkles: :thumbsup: :sparkles:
:cookie: 843 | @garrusnapp |http://www.freecodecamp.com/garrusnapp