function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var target = Object.keys(source);
var key = target[0]; //key = source's key argument
for(var i = 0; i < collection.length; i++){
if(collection[i][key] === source[key]){
arr.push(collection[i]);
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&utf8=1&srsearch=' + searchTerm + '&srwhat=text&srinfo=totalhits&srprop=titlesnippet%7Csnippet
$("element to hide")[0].style.display = "none"
or $("element to hide").hide()
<div class="modal fade" id="myModal">
function sumAll(arr) {
var total = arr.reduce(function(sum, value) {
var i=0;
while (i < value) {
i++;
return i + sum;
}
});
return total;
}
sumAll([1, 4]);
.reduce()
- and return
inside a while loop makes the loop exit immediately
function sumAll(arr) {
var min = Math.min(...arr);
var max = Math.max(...arr);
}
sumAll([1, 4]);
function sumAll(arr) {
var min = Math.min(...arr);
var max = Math.max(...arr);
var i = 0;
while (i < max) {
i++;
}
}
sumAll([1, 4]);
@adamfaraj
function sumAll(arr) {
var min = Math.min(...arr);
var max = Math.max(...arr);
var array = [];
array.push(min);
while (min < max) {
min++;
array.push(min);
}
return array.reduce((sum, value) =>
sum + value );
}
sumAll([5, 10]);
this worked
function sumAll(arr) {
var min = Math.min(...arr),
var max = Math.max(...arr);
var sum = 0;
while (min <= max) {
sum += min++;
}
return sum;
}
sumAll([1, 4]);
$(function(){
window.addEventListener("keypress", doKeyDown);
})();
()
$(init);
function init() {
window.addEventListener("keypress", doKeyDown);
}
$( handler )
, but your code does work if you add the ()
after
cyberpunk1971 sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 223 | @piteto |http://www.freecodecamp.com/piteto
nav ul
though just to be a little more specific and to prevent affecting other <ul> elements on your page later on
h1tag sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 224 | @piteto |http://www.freecodecamp.com/piteto
function filterCards() {
var filterState = states.value;
var filterApproach = approach.value;
/*var selector = this.id == "approach" ? '.space-approach' : '.space-state'; */
var card = $(el).closest('.card-parent');
var titleState = document.getElementsByClassName('space-state');
var titleApproach = document.getElementsByClassName('space-approach');
if(filterState == "All States"){
for (i = 0; i < card.length; i += 1) {
titleApproach[i].includes(titleApproach){
card.show();
} else{
card.hide();
}
return;
}
} else if (filterApproach == "All Learning Methods"){
for (i = 0; i < card.length; i += 1) {
titleState[i].includes(titleState){
card.show();
} else{
card.hide();
}
return;
}
} else{
for (i = 0; i < card.length; i += 1) {
if(titleState[i].includes(filterState) && titleApproach[i].includes(titleApproach)){
card.show();
} else{
card.hide();
}
return;
}
}
@piteto
I'm writing new code. please ignore the top one
@piteto
please look at this code
var states = document.getElementById('state');
var approach = document.getElementById('approach');
[states,approach].addEventListener('change', filterCards);
function filterCards() {
console.log(states.value);
console.log(approach.value);
var filterState = states.value;
var filterApproach = approach.value;
/*var selector = this.id == "approach" ? '.space-approach' : '.space-state'; */
var card = document.getElementsByClassName('card-parent');
var state = document.getElementsByClassName('space-state');
var titleState = Array.from(state);
console.log(titleApproach);
var approach = document.getElementsByClassName('space-approach');
var titleApproach = Array.from(approach);
if(filterState == "All States"){
for (i = 0; i < card.length; i += 1) {
if(titleApproach[i].includes(filterApproach)){
parentnode.parentnode.parentnode.show();
} else{
parentnode.parentnode.parentnode.card.hide();
}
return;
}
}
else if(filterState == "All Learning Methods"){
for (i = 0; i < card.length; i += 1) {
if(titleState[i].includes(filterState)){
parentnode.parentnode.parentnode.card.show();
} else{
parentnode.parentnode.parentnode.card.hide();
}
return;
}
}
else{
for (i = 0; i < card.length; i += 1) {
if(titleState[i].includes(filterState) && titleApproach[i].includes(titleApproach)){
parentnode.parentnode.parentnode.card.show();
} else{
parentnode.parentnode.parentnode.card.hide();
}
return;
}
}
}
var states = document.getElementById('state');
var approach = document.getElementById('approach');
var filterState = states.value;
var filterApproach = approach.value;
var card = document.getElementsByClassName('card-parent');
var statenode = document.getElementsByClassName('space-state');
var titleState = Array.from(statenode);
var approachnode = document.getElementsByClassName('space-approach');
var titleApproach = Array.from(approachnode);
states.addEventListener('change', filterCards);
function filterCards() {
/*var filterState = states.value;
var filterApproach = approach.value; */
/*var selector = this.id == "approach" ? '.space-approach' : '.space-state'; */
if(filterState == "All States" && filterApproach == "All Learning Methods"){
$('.card-parent').show();
return;
}
else if (filterState == "All States"){
for (i = 0; i < card.length; i ++) {
if(titleApproach[i].innerHtml.includes("filterApproach")){
parentnode.parentnode.parentnode.show();
} else{
parentnode.parentnode.parentnode.hide();
}
return;
}
}
else if(filterState == "All Learning Methods"){
for (i = 0; i < card.length; i ++) {
if(titleState[i].innerHtml.includes("filterState")){
parentnode.parentnode.parentnode.show();
} else{
parentnode.parentnode.parentnode.hide();
}
return;
}
}
else{
for (i = 0; i < card.length; i += 1) {
if(titleState[i].innerHtml.includes(filterState) && titleApproach[i].innerHtml.includes(titleApproach)){
parentnode.parentnode.parentnode.show();
} else{
parentnode.parentnode.parentnode.hide();
}
return;
}
}
}
@piteto i was able to do that by doing
var all = [states,approach]
and then doing
all.addEvenlist......
alteducation sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 226 | @piteto |http://www.freecodecamp.com/piteto
function generate(num,arr)
{
if (num===1){
permutations.push(arr.join(''));
}
else{
for (var i=0;i<num-1;i+=1){
generate(num-1,arr);
if(num%2==0){
swap(i,num-1);
}
else{
swap(0,num-1);
}
}
}
}
generate(arr.length,arr);
procedure generate(n : integer, A : array of any):
if n = 1 then
output(A)
else
for i := 0; i < n - 1; i += 1 do
generate(n - 1, A)
if n is even then
swap(A[i], A[n-1])
else
swap(A[0], A[n-1])
end if
end for
generate(n - 1, A)
end if
n = 1
and bubbles up again
output
generate
, when n=1
is reached, a new permutation is printed
<div class="weather-icon"></div>
function getWeather() {
$.ajax({
headers: {
Accept: "application/json",
},
url: "https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139",
success: function(generate) {
$(".weather-icon").text(generate.weather[0].icon);
}
});
}
$(document).ready(function () {
getWeather();
});
Output: "https://cdn.glitch.com/6e8889e5-7a72-48f0-a061-863548450de5%2F01n.png?1499366020783"
How can I get image from this link? Any one help me!
text
put it on a image src
and the image will be displayed @Shaikot007attr
method to change programmatically the src attribute
aguyinmontreal sends brownie points to @cyberputty :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @cyberputty |http://www.freecodecamp.com/cyberputty
@piteto
function filterCards() {
var card = document.getElementsByClassName('card-parent');
var statenode = document.getElementsByClassName('space-state');
var titleState = Array.from(statenode);
var approachnode = document.getElementsByClassName('space-approach');
var titleApproach = Array.from(approachnode);
var filterState = states.value;
var filterApproach = approach.value;
if(filterState == "All States" && filterApproach == "All Learning Methods"){
$('.card-parent').show();
return;
}
else if (filterState == "All States" && filterApproach !== "All Learning Methods"){
for (i = 0; i < card.length; i++) {
titleApproach[i].innerText.includes(filterApproach) ? card[i].style.display = "inline-block" : card[i].style.display = "none";
}
return;
}
else if (filterApproach == "All Learning Methods" && filterState !== "All States"){
for (i = 0; i < card.length; i++) {
titleState[i].innerText.includes(filterState) ? card[i].style.display = "inline-block" : card[i].style.display = "none";
}
return;
}
else{
for (i = 0; i < card.length; i++) {
titleState[i].innerText.includes(filterState) && titleApproach[i].innerText.includes(filterApproach) ? card[i].style.display = "inline-block" : card[i].style.display = "none";
}
return;
}
}
var states = document.getElementById('state');
var approach = document.getElementById('approach');
[states,approach].forEach(function(item){
item.addEventListener('change', filterCards);
});
this is the code that i wrote could you look at it and tell me how i can improve it. i feel like i used too many variables
kbaig sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
:cookie: 360 | @iangracia |http://www.freecodecamp.com/iangracia
kbaig sends brownie points to @iangracia :sparkles: :thumbsup: :sparkles:
innerText
with textContent
. If you want to reduce the list of var
s at the top, remove filterState
and filterApproach
at the beginning and just use states.value
and approach.value
and then combine aproachnode and statenode into titleState and titleApproach.
var card = document.getElementsByClassName("card-parent");
var titleState = Array.from(document.getElementsByClassName("space-state"));
var titleApproach = Array.from(document.getElementsByClassName("space-approach"));
"Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price), payment as the second argument (cash), and cash-in-drawer (cid) as the third argument.
cid is a 2D array listing available currency.
Return the string "Insufficient Funds" if cash-in-drawer is less than the change due. Return the string "Closed" if cash-in-drawer is equal to the change due.
Otherwise, return change in coin and bills, sorted in highest to lowest order."
Test:
checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) should return "Insufficient Funds"
Shouldn't the above test return 0.5?? and not "Insufficient Funds"
iangracia sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 535 | @gersho |http://www.freecodecamp.com/gersho
…
$scope.object = {}
// later use
$scope.object.propertyOne;
$scope.object.propertyTwo;
instead of multiple scopes?
you'll need to use HTTPS (and probably JSONP after that) for that API @Niloy513
angular.min.js:sourcemap:103 Mixed Content: The page at 'https://s.codepen.io/Niloy513/pen/VMQNmd?editors=1011' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en'. This request has been blocked; the content must be served over HTTPS.
niloy513 sends brownie points to @leanjunio and @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 228 | @piteto |http://www.freecodecamp.com/piteto
:cookie: 288 | @leanjunio |http://www.freecodecamp.com/leanjunio
This request has been blocked; the content must be served
over HTTPS.
var app = angular.module("model", []);
app.controller("control", [
"$scope", "$http", function($scope, $http) {
$scope.newquote = () => {
$http.jsonp("https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=showQuote")
};
}
]);
function showQuote(data) {
console.log(data);
}
niloy513 sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
@Niloy513 Totally man, here’s two links to AJAX requests (Basically what you’re trying to make earlier, you were trying to make a GET request to the quote person’s server), this is a great channel for all other stuff btw.
https://www.youtube.com/watch?v=h0ZUpPiV1ac&t=2s
and here’s the FCC vid for AJAX: https://www.youtube.com/watch?v=tHRNuBf_8xg
niloy513 sends brownie points to @piteto :sparkles: :thumbsup: :sparkles: