hi, I want to make it so I add class on scroll, I know this isn't efficient but I understand what is going on.. except I'm a little lost
```js
$(document).ready(function(){
function scroller() {
function aboutAdd() {
var aboutActive = $("#nav-about").addClass(".nav-active");
$("#nav-portfolio").removeClass(".nav-active");
$("#nav-contact").removeClass(".nav-active")
};
function portfolioAdd() {
var aboutActive = $("#nav-portfolio").addClass(".nav-active");
$("#nav-about").removeClass(".nav-active");
$("#nav-contact").removeClass(".nav-active")
};
function contactAdd() {
var aboutActive = $("#nav-contact").addClass(".nav-active");
$("#nav-about").removeClass(".nav-active");
$("#nav-portfolio").removeClass(".nav-active")
};
var aboutPos = $("#about").offset();
var portfolioPos = $("#scroller").offset();
var contactPos = $("#contact").offset();
$(window).on("scroll" , function() {
if (aboutPos > portfolioPos && aboutPos > contactPos {
aboutAdd();
}
else if (portfolioPos > contactPos && portfolioPos < aboutPos){
portfolioAdd();
}
else if(contactPos < portfolioPos && contactPos < aboutPos){
contactAdd();
}
else{
$("#nav-about"),removeClass(".nav-active") ;
$("#nav-portfolio").removeClass(".nav-active");
$("#nav-contact").removeClass(".nav-active");
}
});
};
});
```js
$(document).ready(function(){
function scroller() {
function aboutAdd() {
var aboutActive = $("#nav-about").addClass(".nav-active");
$("#nav-portfolio").removeClass(".nav-active");
$("#nav-contact").removeClass(".nav-active")
};
function portfolioAdd() {
var aboutActive = $("#nav-portfolio").addClass(".nav-active");
$("#nav-about").removeClass(".nav-active");
$("#nav-contact").removeClass(".nav-active")
};
function contactAdd() {
var aboutActive = $("#nav-contact").addClass(".nav-active");
$("#nav-about").removeClass(".nav-active");
$("#nav-portfolio").removeClass(".nav-active")
};
var aboutPos = $("#about").offset();
var portfolioPos = $("#scroller").offset();
var contactPos = $("#contact").offset();
$(window).on("scroll" , function() {
if (aboutPos > portfolioPos && aboutPos > contactPos {
aboutAdd();
}
else if (portfolioPos > contactPos && portfolioPos < aboutPos){
portfolioAdd();
}
else if(contactPos < portfolioPos && contactPos < aboutPos){
contactAdd();
}
else{
$("#nav-about"),removeClass(".nav-active") ;
$("#nav-portfolio").removeClass(".nav-active");
$("#nav-contact").removeClass(".nav-active");
}
});
};
});
$("#weather").html("City: " + data.name+data.main.temp);
$("#weather").append("<p>Weather: " + data.weather[0].main + "</p>");
}
$("#weather").html("City: " + data.name+ <span class="myclass">data.main.temp<span> );
$("#weather").append("<p>Weather: " + data.weather[0].main + "</p>");
}
$("#weather").html("City: " + data.name+ <span class="myclass">data.main.temp</span> );
$("#weather").html("City: " + data.name+
"<span class="myclass">"+data.main.temp+"</span>" );
nixonrichard sends brownie points to @sorinr :sparkles: :thumbsup: :sparkles:
:cookie: 468 | @sorinr |http://www.freecodecamp.com/sorinr
<div id="weather">
<div id="temp">
<p class="center">Click the button to get your local weather.</p></div></div>
<div class="center-div">
$("#weather").html("City: " + data.name
);$("#weather").html("City: " + data.name
);
$("#temp").html("Temperature:" +data.main.temp);
$("#weather").append("<p>Weather: " + data.weather[0].main + "</p>");
}
<div id="weather">
<div id="temp">
<p class="center">Click the button to get your local weather.</p>
</div>
</div>
buiphuking sends brownie points to @sorinr :sparkles: :thumbsup: :sparkles:
:cookie: 469 | @sorinr |http://www.freecodecamp.com/sorinr
absolutezero273 sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 690 | @gregatgit |http://www.freecodecamp.com/gregatgit
@GregatGit ```js
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));</script>```
Do I not have to use this at all?
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
['a', 'b', 'c'] convert to
[['a'],['b'],[c']]
Hi, can someone help me?
This is my code:
$(document).ready(function() {
$("#randomBtn").on("click",function(){
var answer="";
var random= Math.floor(Math.random() * (3)+1);
switch(random) {
case 1:
answer=['"La mujer es como la polvora, si no la tratas con cuidado, explota"', "Miguel Moyá"];
break;
case 2:
answer= ['"Y los españoles, muy españoles y mucho españoles!!"', "Rajoy"];
break;
case 3:
answer= ['"El mundo esta dividido en tres grandes grupos, el de los que sabe contar, y el de los que no."',"Homer J. Simpson"];}
$(".message").html(answer[0]);
$(".name").html(answer[1]);
var tweet= "https://twitter.com/intent/tweet?text=+";
answer=answer[0].split(" ");
answer=answer[0].join("%20");
tweet+= answer[0];
tweet+= "%20"+ answer[1];
console.log(answer);
$("#tweetBtn").attr("href",tweet);
});
});
My problem is that $("#tweetBtn").attr("href",tweet); don't work, also I write console.log(answer); for search problems, and console don't print anything
;_(
help please
kevinkuehler sends brownie points to @dueldrawer8 :sparkles: :thumbsup: :sparkles:
:cookie: 411 | @dueldrawer8 |http://www.freecodecamp.com/dueldrawer8
dueldrawer8 sends brownie points to @kevinkuehler :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @kevinkuehler |http://www.freecodecamp.com/kevinkuehler
flyyyperth sends brownie points to @benalron and @codergeek700 :sparkles: :thumbsup: :sparkles:
:cookie: 30 | @codergeek700 |http://www.freecodecamp.com/codergeek700
:cookie: 371 | @benalron |http://www.freecodecamp.com/benalron
function mutation(arr) {
return arr;
}
mutation(['hello', 'hey']);
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
more info:
bf details
|bf links
|hint
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
@CarlosFerrerCeldran add this on your css
.text-centers{
position: relative;
right:-20px;
}
and replace your text-center class of the list with text-centers
pizzapgh sends brownie points to @sorinr :sparkles: :thumbsup: :sparkles:
:cookie: 470 | @sorinr |http://www.freecodecamp.com/sorinr
is there a shorthand in sass /scss for the following: I defined
$colors: #A8E0E1,#5A96BB,#75448C,#C46CAA;
and I want to access them by place for example
body{
background-color: nth($colors,1);
}
Ofcourse this works but is there a shorter way to do it ?
:cookie: 473 | @sorinr |http://www.freecodecamp.com/sorinr
wo1v3r sends brownie points to @sorinr :sparkles: :thumbsup: :sparkles:
yodermail sends brownie points to @mkrump :sparkles: :thumbsup: :sparkles:
:cookie: 201 | @mkrump |http://www.freecodecamp.com/mkrump
francescadd sends brownie points to @wo1v3r :sparkles: :thumbsup: :sparkles:
:cookie: 280 | @wo1v3r |http://www.freecodecamp.com/wo1v3r
shivam13 sends brownie points to @wo1v3r :sparkles: :thumbsup: :sparkles:
:cookie: 281 | @wo1v3r |http://www.freecodecamp.com/wo1v3r
yodermail sends brownie points to @wo1v3r :sparkles: :thumbsup: :sparkles:
:cookie: 282 | @wo1v3r |http://www.freecodecamp.com/wo1v3r
shivam13 sends brownie points to @sorinr :sparkles: :thumbsup: :sparkles:
:cookie: 474 | @sorinr |http://www.freecodecamp.com/sorinr
""
around image src see below for reference<img class="img-responsive" src="' + userImage + '" width="300" height="300">
pae4557 sends brownie points to @mirabalj and @vinaypuppal :sparkles: :thumbsup: :sparkles:
:cookie: 417 | @vinaypuppal |http://www.freecodecamp.com/vinaypuppal
:cookie: 355 | @mirabalj |http://www.freecodecamp.com/mirabalj
var url = "api.openweathermap.org/data/2.5/weather?lat=" + latitude+"&lon="+longitude+"&appid=5811a808db020c08d96e634ccf09bb52";
$.getJSON(url,function(data){
var location = data.name;
});
console.log(location);
var url = "api.openweathermap.org/data/2.5/weather?lat=" + latitude+"&lon="+longitude+"&appid=5811a808db020c08d96e634ccf09bb52";
$.getJSON(url,function(data){
conditions = data.name;
});
console.log(conditions);
$.getJSON(url,function(data){
var location = data.name;
logToConsole(location)
});
function logToConsole(location) {
console.log(location)
}
<ul class="navbar nav">
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT</a></li>
<li><a href="#">PORTFOLIO</a></li>
</ul>
.text()
to get the text of the quote + author from the page. encodeURIComponent($('#quote').text() + ' ~ ' + $('#author').text())
function randomQuote() {
var random = quotes[Math.floor(Math.random() *quotes.length)];
$("#thisquote").text(random.quote);
$("#thisauthor").text("-" +random.author);
};
function changeColor() {
var change = colors[Math.floor(Math.random() *colors.length)];
$('body').css("background", change);
$('#getQuote').css("background", change);
};
$('.btn').click(function() {
randomQuote();
$("#header").remove();
if ( quotes["author"] == "Kramer") {
$("body").css("background-image", "linear-gradient(to top, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),url('file:C:/Users/user/Desktop/freecodecamp/random quote/images/kramer.jpg'");
};
});
elminsterrr sends brownie points to @samosale :sparkles: :thumbsup: :sparkles:
:cookie: 660 | @samosale |http://www.freecodecamp.com/samosale
quotes
object?
var quotes = [{
"quote":"Boy, these pretzels are makin' me thirsty.",
"author":"Kramer"
},
{
"quote":"If you know what happened in the Mets game don't tell me, I taped it. Hello?",
"author":"Jerry"
},
{
"quote":"It became very clear to me sitting out there today that every decision I've made in my entire life has been wrong. My life is the complete opposite of everything I want it to be. Every instinct I have, in every aspect of life, be it something to wear, something to eat - it's all been wrong.",
"author":"George"
},
{
"quote":"I'm not a lesbian. I hate men, but I'm not a lesbian",
"author":"Elaine"
},
{
"quote":"Looking at cleavage is like looking at the sun. You don't stare at it. It's too risky. Ya get a sense of it and then you look away.",
"author":"Jerry"
},
{
"quote":"You have the chicken, the hen, and the rooster. The chicken goes with the hen... So who is having sex with the rooster",
"author":"Frank Costanza"
},
{
"quote":"The cat - mrrreeeooowww - is out of the bag!",
"author":"Kramer"
},
{
"quote": "Jerry, just remember, it's not a lie if you believe it.",
"author": "George"
},
{
"quote": "Do you ever get down on your knees and thank God you know me and have access to my dementia",
"author": "George"
},
{
"quote": "We don't know how long this will last. They are a very festive people.",
"author": "Elaine"
},
{
"quote": "You know I always wanted to pretend I was an architect.",
"author": "George"
},
{
"quote": "If you're not gonna be a part of a civil society, then just get in your car and drive on over to the East Side.",
"author": "Kramer"
},
{
"quote": "I'm speechless. I have no speech.",
"author": "George"
},
{
"quote": "I have been performing feats of strength all morning.",
"author": "Frank Costanza"
},
{
"quote": "I lie every second of the day. My whole life is a sham.",
"author": "George"
},
{
"quote": "Hi, my name is George, I'm unemployed and I live with my parents.",
"author": "George"
},
{
"quote": "Just remember, when you control the mail, you control... information.",
"author": "Newman"
},
{
"quote": "I don't trust the guy. I think he regifted, then he degifted, and now he's using an upstairs invite as a springboard to a Super bowl sex romp.",
"author": "Jerry"
},
{
"quote": "I don't think I've ever been to an appointment in my life where I wanted the other guy to show up.",
"author": "George"
},
{
"quote": "Boy, a little too much chlorine in that gene pool.",
"author": "Jerry"
},
{
"quote": "Do you have any idea how much time I waste in this apartment?",
"author": "Kramer"
},
{
"quote": "See, this is what the holidays are all about. Three buddies sitting around chewing gum.",
"author": "Kramer"
},
{
"quote": "The carpet sweeper is the biggest scam perpetrated on the American public since One Hour Martinizing.",
"author": "Kramer"
},
{
"quote": "Here's to feeling good all the time.",
"author": "Kramer"
},
{
"quote": "I'll be back. We'll make out.",
"author": "David Puddy"
},
{
"quote": "Ah, look, I? I'm sorry to bother you, but I'm a US postal worker and my mail truck was just ambushed by a band of backwoods mail-hating survivalists.",
"author": "Newman"
},
{
"quote": "You very bad man, Jerry. Very bad man.",
"author": "Babu"
},
]
willcodes sends brownie points to @samosale :sparkles: :thumbsup: :sparkles:
:cookie: 661 | @samosale |http://www.freecodecamp.com/samosale
quotes[random]["author"]
Using jQuery, you can change the text between the start and end tags of an element. You can even change HTML markup.
jQuery has a function called .html()
that lets you add HTML tags and text within an element. Any content previously within the element will be completely replaced with the content you provide using this function.
Here's how you would rewrite and italicize the text of our heading:
$("h3").html("<em>jQuery Funhouse</em>");
jQuery also has a similar function called .text()
that only alters text without adding tags. So when using .html()
please remember that you will be editing the whole markup and not just the text.
:pencil: read more about challenge change text inside an element using jquery on the FCC Wiki