marcgraci sends brownie points to @mot01 :sparkles: :thumbsup: :sparkles:
var arr = [a,b,c,d];
how do i get c?
var arr = [a, b, {description: cloudy, temp: 56} ,d]
arr[2] = {description: cloudy, temp: 56}
weather = [{description: tornado}]
yow fam on my repl.it i am returning the right objects but when i paste everything on fcc theres a incorrect return value. heres my code:
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold",
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));
// Only change code below this line
function updateRecords(id, prop, value) {
if(prop !== 'tracks' && value !== '') {
collection[id][prop] = value;
}
else if(prop === 'tracks' && !collection[id].hasOwnProperty('tracks') ) {
collection.tracks = [value];
}
else if(prop === 'tracks' && value !== '') {
collection[id].tracks.push(value);
}
else if(value === '') {
delete collection[id][prop];
}
return collection;
}
updateRecords(5439, "tracks", "Take a Chance on Me");//tracks should have "Take a Chance on Me" as the last element.
this is the culprit. but i think its a bug.
updateRecords(5439, "tracks", "Take a Chance on Me");//tracks should have "Take a Chance on Me" as the last element.
androbat sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:star2: 1136 | @roxroy |http://www.freecodecamp.com/roxroy
for(var i = 0; i < info[1].length; i++) {
console.log(info[1][0])
}
for (var i=0; i<info[0].length; i++){
#ouput.append('div'+info[0][i]+'/div')
display: inline
or display: inline-block
.prepend("<img src='"+ data3.logo + "'>")
.prepend("<div>" + data3.name+ "</div>")
.prepend("<div>" + data3.status + "</div>");
} else {
var logo= "http://res.cloudinary.com/mers/image/upload/c_scale,w_400/v1504573315/ui-day033-404error_u37kee.png";
$("#followerinfo")
.prepend("<img src='"+ logo + "'>")
.prepend("<div>" + data3.message+ "</div>")
.prepend("<div>" + data3.error + "</div>");
}});
<div> //make this block
<logo> //inline
<title> //inline
</div>
$("#followerinfo").append('<div class="block">
<img src="'+imgHere+'" class="inline">
<div class="inline">' + data3.status + '</div>
</div>');
mers89 sends brownie points to @mot01 :sparkles: :thumbsup: :sparkles:
:cookie: 840 | @mot01 |http://www.freecodecamp.com/mot01
nxdl sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 419 | @gothamknight |http://www.freecodecamp.com/gothamknight
nxdl sends brownie points to @mot01 :sparkles: :thumbsup: :sparkles:
:cookie: 841 | @mot01 |http://www.freecodecamp.com/mot01
.append
li
to the list. Use the jQuery .append() function. See http://api.jquery.com/append/ to see how it works
rafaelmonroy sends brownie points to @mot01 and @roxroy :sparkles: :thumbsup: :sparkles:
:star2: 1137 | @roxroy |http://www.freecodecamp.com/roxroy
:cookie: 842 | @mot01 |http://www.freecodecamp.com/mot01
rafaelmonroy sends brownie points to @mot01 :sparkles: :thumbsup: :sparkles:
:warning: rafaelmonroy already gave mot01 points
hillsie sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 547 | @longnt80 |http://www.freecodecamp.com/longnt80
let circ = document.getElementById("circle")
let circle= document.createElement('circle')
circle.setAttribute('cx', 100)
circle.setAttribute('cy', 100)
circle.setAttribute('r', 20)
circ.appendChild(circle)
VM290 pen.js:6 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
at createCircle (VM290 pen.js:6)
at HTMLButtonElement.onclick (index.html?editors=0011:9)
that's the error I got
hashtagyolo1 sends brownie points to @janshah :sparkles: :thumbsup: :sparkles:
:cookie: 511 | @janshah |http://www.freecodecamp.com/janshah
Node.appendChild()
. I think .append()
is a jQuery method.
var age=Number(prompt("your age"));
if (age<0) {
console.log("error" );
}
else if(age===21) {
console.log("happy 21st birthday");
}
else if (age%2==1) {
console.log("your age is odd");
}
else(age % Math.sqrt(age) === 0) {
console.log("your age is perfect square");
}
else
is like a default output so you do not need a conditional for it. I never have anyway (although that is not saying much)
(age % Math.sqrt(age) === 0)
that
trellowhoomer sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 420 | @gothamknight |http://www.freecodecamp.com/gothamknight
var age = prompt("What is your age?");
if (age < 0) {
console.log("error" );
} else if (age === 21) {
console.log("happy 21st birthday");
} else if (age % 2 == 1) {
console.log("your age is odd");
} else (age % Math.sqrt(age) === 0)
console.log("your age is perfect square");
function createCircle(){
var cx1 = Math.floor(Math.random() * (50 - 5));
var cy1 = Math.floor(Math.random() * (50 - 5));
var r1 = Math.floor(Math.random() * (10 - 2));
//$("#circle").append("<p>test</>");
$("#circle").append("<svg viewBox="0 0 200 200"><circle cx='" + cx1 + "' cy='" + cy1 + "' r='" + r1 + "' /></svg>");
}
Getting an unexpected number error, but I can't work why
else (age % Math.sqrt(age) === 0)
console.log("your age is perfect square");
else
should be else if
. Or just if
.
@hashtagyolo1 ´$('.input').autocomplete({
source: function(query, result){
$.ajax({
url: "http://en.wikipedia.org/w/api.php",
dataType: "jsonp",
data: {
'action': "opensearch",
'format': "json",
'search': query.term
},
success: function (data) {
console.log(data)
}
});
}
});
´ CONSOLE.LOG(data ) is not responde Iam try to get data from the Weakipedia API
nicolnonga sends brownie points to @hashtagyolo1 and @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 421 | @gothamknight |http://www.freecodecamp.com/gothamknight
:cookie: 272 | @hashtagyolo1 |http://www.freecodecamp.com/hashtagyolo1
trellowhoomer sends brownie points to @lydatech :sparkles: :thumbsup: :sparkles:
:star2: 2406 | @lydatech |http://www.freecodecamp.com/lydatech
krckyboy sends brownie points to @just1witness :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @just1witness |http://www.freecodecamp.com/just1witness
krckyboy sends brownie points to @vramazing :sparkles: :thumbsup: :sparkles:
:cookie: 121 | @vramazing |http://www.freecodecamp.com/vramazing
text-align: center;
in your css to center things - one way anyway
@jatacid
those questions are javascript related?
"Do you know what's the difference between a static, dynamic and persistent variable" and "what are the benefits of using a closure?"
var pointK = {
"Moscow":1,
"Samara":1.1
}
var deliveryStore = [];
function registerDelivery(obj){
var cash;
if(Array.isArray(obj)) {
obj.map(function(x) {
obj = x;
});
}
var delivery = Math.floor (obj.price*0.015*pointK[obj.destination]+175);
deliveryStore.push(obj, delivery);
}
registerDelivery([{
product: 'Canon EOS 1500D Kit 18-55mm DC black',
price: 22999,
destination: 'Moscow',
count: 1
},
{
product: 'Canon EOS 1200D Kit 18-55mm DC black',
price: 15000,
destination: 'Samara',
count: 1
}]);
console.log(deliveryStore);
obj.map(function(x) {
obj = x;
});
for(var i = 0; i < obj.length; i++) {
deliveryStore.push(obj[i], Math.floor (obj[i].price*0.015*pointK[obj[i].destination]+175);
}
for(var i = 0; i < obj.length; i++) {
deliveryStore.push([obj[i], Math.floor (obj[i].price*0.015*pointK[obj[i].destination]+175]);
}
marat89bluolyu sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 451 | @korzo |http://www.freecodecamp.com/korzo
var url =
"https://api.darksky.net/forecast/8bfe73adbee0a652190e6c9ccd1e1d21/" +
lat +
"," +
long +
"?exclude=minutely,hourly,daily,alerts,flags&units=si&callback=?";
$.ajax({
url: url,
type: "GET",
async: false,
dataType: "json",
success: function(data, status) {
// do some magic with data
}
1532j0004kg sends brownie points to @orangekulture :sparkles: :thumbsup: :sparkles:
:cookie: 460 | @orangekulture |http://www.freecodecamp.com/orangekulture
```
function logMe(name){
console.log(name)
}
function logMe(car){
console.log(car)
}
logMe(mercedes);
``
krckyboy sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 56 | @piteto |http://www.freecodecamp.com/piteto
hey guys, quick question, for img.src, is it possible to turn this into an array? http://www.williammalone.com/briefs/how-to-draw-image-html5-canvas/
for example, would the following code be valid?
img.src = [
'images/image1.png',
'images/image2.png',
'images/image3.png'
];
amitp88 sends brownie points to @just1witness :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @just1witness |http://www.freecodecamp.com/just1witness
img {
src: [img1, img2...]
}
amitp88 sends brownie points to @mot01 and @just1witness :sparkles: :thumbsup: :sparkles:
:warning: amitp88 already gave just1witness points
:cookie: 843 | @mot01 |http://www.freecodecamp.com/mot01
amitp88 sends brownie points to @just1witness :sparkles: :thumbsup: :sparkles:
:warning: amitp88 already gave just1witness points
let images = [
'images/image1.png',
'images/image2.png',
'images/image3.png'
];
images.forEach( function(image){
let img = new Image();
img.onload = function () {
context.drawImage(img, 100, 100, 150, 110, 0, 0, 300, 220);
}
img.src = image;
}
@cmccormack I was brainstorming possible workarounds and I came up with this:
var tileImg = [
'images/tiles/orbs/physical.png',
'images/tiles/orbs/thunder.png',
'images/tiles/orbs/fire.png',
'images/tiles/orbs/earth.png',
'images/tiles/orbs/light.png',
'images/tiles/orbs/water.png',
'images/tiles/orbs/dark.png',
];
img.src = function () {
tileImg[Math.floor(Math.random() * 7) + 0];
};
var img = new Image();
img.onload = function () {
ctx.drawImage(img, 0, 0);
}
However, no matter how I set img.src, it seems like if it's anything but an image URL I'll get 'Cannot set property 'src' of undefined'
function randRangeInt(m, n){
return Math.floor((Math.random() * (n+1-m)) + m)
}
then you can call
tileImg[randRangeInt(0, tileImg.length)]
or however you want to do it
this
Correction btw:
tileImg[randRangeInt(0, tileImg.length)]
should be
tileImg[randRangeInt(0, tileImg.length-1)]
var img = new Image();
img.onload = function() {
ctx.drawImage(img, 0, 0 )
}
img.src = 'images/image.png';
https://codepen.io/cmccormack/pen/ZJZxJJ
amitp88 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1185 | @cmccormack |http://www.freecodecamp.com/cmccormack
var img = new Image();
not var img = new Images();
:)
Image
code is wrapped in function that can then be reused for whatever you need
&text=
parameter
$("#btn-tweet").attr("href", twitter_url + quote + ... )
, convert to vanilla as necessary
@Feldbot https://dev.twitter.com/web/intents
<script type="text/javascript" async src="https://platform.twitter.com/widgets.js"></script>
<a href="https://twitter.com/intent/tweet?in_reply_to=463440424141459456">Reply</a>
<a href="https://twitter.com/intent/retweet?tweet_id=463440424141459456">Retweet</a>
<a href="https://twitter.com/intent/like?tweet_id=463440424141459456">Like</a>
This part of the documentation is really all you need to complete the web intent. I only used the first two lines in my project
"https://twitter.com/intent/tweet?related=freecodecamp&text="
$("#btn-tweet").attr("href", twitter_url + quote + ... )
feldbot sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1186 | @cmccormack |http://www.freecodecamp.com/cmccormack
@Feldbot If you want to use the official twitter button you just need a div in your HTML:
<div id="tweet"></div>
And this line in your JS:
twttr.widgets.createShareButton("/", document.getElementById('tweet'), {size: "large", text: $('#quote-content').text()});
amitp88 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: amitp88 already gave cmccormack points
let i=0...
and let j=0;...
in your loops
feldbot sends brownie points to @pieto and @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: @pieto's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:warning: feldbot already gave cmccormack points
amitp88 sends brownie points to @trommelochse :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @trommelochse |http://www.freecodecamp.com/trommelochse
amitp88 sends brownie points to @trommelochse :sparkles: :thumbsup: :sparkles:
:warning: amitp88 already gave trommelochse points
https://codepen.io/cmccormack/pen/LjvmKZ
I was meaning to make a sample for this anyway, hope it helps
var test = [{
product: 'Canon EOS 1300D Kit 18-55mm DC',
price: 22999,
destination: 'Samara',
count: 1
},
{
product: 'Canon EOS 1200D Kit 18-55mm DC',
price: 15000,
destination: 'Moscow',
count: 1
},
{
product: 'Canon EOS 1300D Kit 18-55mm DC',
price: 22999,
destination: 'Samara',
count: 2
}
]
function getObjReport(test) {
for (var i = 0; i < test.length; i++) {
for (var j = 1; j < test.length; j++) {
if (test[j].destination != test[i].destination){
console.log(test[i].destination);
console.log(test[j].destination);
} else {
console.log(test[i].destination)
}
}
}
}
getObjReport(test);
var j = i + 1
in your second loop
test.length-1
in the first loop as well
$("#btn-tweet").attr("href", twitter_url + quote + ... )
feldbot sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: feldbot already gave cmccormack points
test.lenght-1
for j
?
i
- you don't want to compare the last element with anything outside of your array :)
@Feldbot
$("#btn-tweet").attr("href", twitter_url + quote + ... )
is equivalent to
document.getElementById('btn-tweet').href = 'https://twitter.com/intent/tweet?text=' + quote + ...
where ...
is anything else you want to add like author or whatever.
test.detination
1 time if i have several identical values
// Moscow:
// Canon EOS 1300D Kit 18-55mm DC ',price= 22999 , quantity=1 . = delivery 519 .
// Samara:
// Canon EOS 1200D Kit 18-55mm DC ', price=22999 ,quantity=1 2 . = delivery 1108 .
// Canon EOS 1200D Kit 18-55mm DC ', price=22999 ,quantity=1 2 . = delivery 1108.
// Canon EOS 1200D Kit 18-55mm DC ',price= 22999 , quantity=12 . = delivery 1108.
// Total: 3843 .
@Marat89bluolyu ah. So what you can do is create a new object that you store these product objects in. As you iterate your array, you can do something like
newObj[test[i].destination].push(test[i])
You should check if the destination exists prior to this by doing something like
if (!newObj.hasOwnProperty(test[i].destination){
newObj[test[i].destination] = [ test[i] ]
} else {
newObj[test[i].destination].push(test[i])
}
This way you don't even have to compare objects - if your new object doesn't have a property for that destination
marat89bluolyu sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1187 | @cmccormack |http://www.freecodecamp.com/cmccormack
feldbot sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1189 | @cmccormack |http://www.freecodecamp.com/cmccormack
.socialMedias a
. No need for duplicate code
.socialMedias a
bottom: 0;
to .socialMedias a:before
erichasegawa sends brownie points to @korzo :sparkles: :thumbsup: :sparkles: