:bulb: to format code use backticks! ``` more info
function queue(arr, item) {
// Your code here
return arr.push(item);
return arr.shift();
// Change this line
}
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
```js ⇦ Type 3 backticks and then press [shift + enter ⏎]
(type js or html or css)
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
robmo sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 400 | @jnmorse | http://www.freecodecamp.com/jnmorse
function queue(arr, item) {
// Your code here
return arr.push(item);
return arr.shift();
// Change this line
}
array.push()
returns the updated length of the array, array.shift()
returns the item removed from the array
function sumAll(arr) {
arr.reduce();
return arr;
}
sumAll([1, 4]);
andrewchar sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 401 | @jnmorse | http://www.freecodecamp.com/jnmorse
robmo sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:warning: robmo already gave jnmorse points
Any ideas on why I can't seem to use my "weather" variable outside of the defineWeather() function, even though I initialized it outside of the function?
$(document).ready(function() {
var weather = {};
$.getJSON("http://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=57848e1dd9f80f39b83c8b46e5bc54fb&units=metric", defineWeather)
function defineWeather(data) {
weather = data;
$("#temp").html(weather.main.temp);
}
});
For example, if I try to move my line with $("#temp") ... outside of the function, it stops working.
kaizen711 sends brownie points to @jerlich97 :sparkles: :thumbsup: :sparkles:
:star: 311 | @jerlich97 | http://www.freecodecamp.com/jerlich97
callback=?
to your query string and it won't give you that error anymore, unfortunately i don't know enough about server stuff to know why
@jerlich97
$(document).ready(function() {
$.getJSON(
"http://en.wikipedia.org/w/api.php?callback=?&action=query&format=json&list=search&utf8=1&srsearch=" + "Albert" + "callback=?",
function(json) {
console.log("testing");
console.log(json);
});
});
did you change it like that
kwhms sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 402 | @jnmorse | http://www.freecodecamp.com/jnmorse
function defineWeather(data) {
extractData(data);
}
function extractData(d){
weather = d;
}
$("#temp").html(weather.main.temp);
$("#temp").html(weather.main.temp);
would need to be in your extractData function instead though cause the value now only exists in those two functions
The smallest common multiple between two numbers is the smallest number that
both numbers can divide into. This concept can be extended to more than two
numbers as well.
We can first start with just finding the smallest common multiple between two
numbers. Naively, you can start writing out multiple of each number until you
write a multiple that exists from both numbers.
An example would be the numbers 3
and 4
. The multiples of 3
are 3, 6, 9,
12, 15, 18, ...
and the multiples of 4
are 4, 8, 12, 16, 20, ...
. The
first smallest number we run into in both lists is 12
so this is the smallest
common multiple between 3
and 4
.
This problem can be confusing because most people look for the smallest common
multiple of just the two numbers but forget the keyword range. However, this
means that if you are given [1,5]
, then you have to check for the smallest
common multiple for all the numbers [1,2,3,4,5]
that is evenly divisible by
all of them.
:pencil: read more about algorithm smallest common multiple on the FCC Wiki
blayman sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 403 | @jnmorse | http://www.freecodecamp.com/jnmorse
/*
* Jquery Smooth Scroll
* Author: Chris Coyier
* URL: https://css-tricks.com/snippets/jquery/smooth-scrolling/
*/
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top - $('#navbar').height() * 3
}, 1000);
return false;
}
}
});
bitgrower sends brownie points to @lubien :sparkles: :thumbsup: :sparkles:
:star: 152 | @lubien | http://www.freecodecamp.com/lubien
hello guys ! I have made some progress with my pomodoro timer, got the session length and display working pretty well...I want to proceed to the break section and wanted to ask you guys
Should I do it just like I did session aspect or there's a better way around it, looking forward to your response(s), sorry I have to direct you to my JSFiddle ....
https://jsfiddle.net/wtwgpmpg/14/
thanks for your time.
lumexralph sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 982 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
time
reaches zero, you'll update it with the value of work or break session length. to make this work, you'll also need a variable that tracks whether the clock is currently in the work or break mode (and you'll need to flip it accordingly). when you update time
with a new value, on the next tick of the interval the clock will simply start counting from there
lumexralph sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1433 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
$(".box").click(function(event) {
var input =$(event.target).text();
seq = seq.concat(input);
try {
var res = eval(seq);
$(".result").text(res);
}
catch (e) {
reg = new RegExp("\d[+-*/]$");
console.log(seq.test(reg));
if(seq.test(reg)=="pass"){
} else {
$(".result").text("INVALID");
}
}
});
Links to useful RegEx resources.
See also: :clipboard: Tutorials | :syringe: Testing | :soccer: Games | :newspaper: Blogs | :package: Software
\d[+\-*\/]$
via a checker. So basically it should match an intermediate expression "4+" would pass.
codernoob sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 274 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
to be clear i set it up like this:
<div class="container-fluid">
<div class="row">
<table id="calculator">
Hi, I'm CamperBot! I can help you in this chatroom :smile:
find TOPIC
find all entries about topic. ex: find js
wiki TOPIC
show contents of topic pagethanks @username
send brownie points to another userabout @username
shows info on that userAlgorithm BONFIRENAME
info on a Algorithm:speech_balloon: meet CamperBot in this room!
media queries
or use bootstrap
col-md-4
doesn't seem to working
rohitchoudharyindia sends brownie points to @dshgna :sparkles: :thumbsup: :sparkles:
:star: 154 | @dshgna | http://www.freecodecamp.com/dshgna
/w/api.php?action=query&format=json&prop=info&list=search&meta=&indexpageids=1&iwurl=1&inprop=url%7Cdisplaytitle&srsearch=Robert+Burns&srnamespace=0&srinfo=rewrittenquery
I added a click trigger and now the draw message appears twice ! Can anyone tell me why?
if (boardFull(movesSign)) { // Show draw game message
$(".winner").append("<p>Draw Game!</p>");
setTimeout(function() {
$('#reset').trigger('click');
}, 2000);
}
if(!boardFull(movesSign)){
aiTurn(); //Switch to AI to take it's turn
}
userTurn
function
function userTurn(pos) {
if ($("#b" + pos).hasClass("clicked")) { // Square is filled
//do nothing
} else {
if (!boardFull(movesSign) && !score(movesSign)) {
takeTurn(pos, userSign); //Make the user's move
$("#b" + pos).addClass("userClicked"); // Add blue background to user clicked boxes
aiTurn(); //Switch to AI to take it's turn
}
}
};
function userTurn(pos) {
if ($("#b" + pos).hasClass("clicked")) { // Square is filled
//do nothing
} else {
if (!boardFull(movesSign) && !score(movesSign)) {
takeTurn(pos, userSign); //Make the user's move
$("#b" + pos).addClass("userClicked"); // Add blue background to user clicked boxes
if(!boardFull(movesSign)){
aiTurn(); //Switch to AI to take it's turn
}
}
}
};
codernoob sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:star: 15 | @alexgaudiosi | http://www.freecodecamp.com/alexgaudiosi
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<script>
$(document).ready(function() {
$(".wikiSearch").on("click", function() {
//var wiki = "https://en.wikipedia.org/w/api.php?action=opensearch&search=Te";
$.getJSON(http://ip.jsontest.com/?callback=showMyIP), function(json) { //IPtest
$(".results").html(JSON.stringify(json));
});
});
});
</script>
<a href="http://en.wikipedia.org/wiki/Special:Random" target="_blank"><button>Random Article</button></a>
<!--<input type="text" id="wikiSearch">-->
<button class="wikiSearch">Test</button>
<div class="results"></div>
</body>
</html>
tstusr441 sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:star: 17 | @alexgaudiosi | http://www.freecodecamp.com/alexgaudiosi
$.getJSON('http://ip.jsontest.com/?callback=showMyIP', function(json) { //IPtest
$(".results").html(JSON.stringify(json));
});
tstusr441 sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:warning: tstusr441 already gave alexgaudiosi points
var code= "function titleCase(str) {
str=str.toLowerCase();
var arr=str.split(" ");
var s="";
for(var i=0;i<arr.length;i++){
for(var j=0;j<arr[i].length;j++){
if(j===0)
s=s+arr[i][j].toUpperCase();
else
s=s+arr[i][j];
}
s=s+" ";
}
return s;
}
titleCase("I'm a little tea pot");
";
function titleCase(str) {
str=str.toLowerCase();
var arr=str.split(" ");
var s="";
for(var i=0;i<arr.length;i++){
for(var j=0;j<arr[i].length;j++){
if(j===0)
s=s+arr[i][j].toUpperCase();
else
s=s+arr[i][j];
}
s=s+" ";
}
return s;
}
titleCase("I'm a little tea pot");
$(document).ready(function() {
$("#getMessage").on("click", function() {
$.getJSON("api.openweathermap.org/data/2.5/forecast/weather?q=London&APPID=2dece6437b9269efec3f645327f480d2", function(json) {
$(".message").html(JSON.stringify(json));
});
});
});
<button id="getMessage">Click me</button>
<div class="message"></div>
http://api.openweathermap.org/data/2.5/forecast/weather?q=London&APPID=2dece6437b9269efec3f645327f480d2
try console.log(json);
@db001
db001 sends brownie points to @rohitchoudharyindia and @tstusr441 and @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 503 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
:star: 244 | @tstusr441 | http://www.freecodecamp.com/tstusr441
:star: 290 | @rohitchoudharyindia | http://www.freecodecamp.com/rohitchoudharyindia
var mySound = new Audio('https://example.com/sound.mp3');
mySound.play();
otmeek sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1434 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
otmeek sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:star: 18 | @alexgaudiosi | http://www.freecodecamp.com/alexgaudiosi
divaweb sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:star: 19 | @alexgaudiosi | http://www.freecodecamp.com/alexgaudiosi
$.ajax({url:'https://api.twitch.tv/kraken/channels/CHANNELNAMEHERE',success:function(data){console.log(data)}});
mikenaza sends brownie points to @jayuhasz :sparkles: :thumbsup: :sparkles:
:star: 306 | @jayuhasz | http://www.freecodecamp.com/jayuhasz
dhcodes sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:star: 20 | @alexgaudiosi | http://www.freecodecamp.com/alexgaudiosi
$("#getMessage").on("click", function(){
$.getJSON("api.openweathermap.org/data/2.5/weather?lat=35&lon=39", function (json){
$(".message").html(JSON.stringify(json));
});
});
$("#getMessage").on("click", function(){
$.getJSON("http://api.openweathermap.org/data/2.5/weather?callback=?&lat=35&lon=39", function (json){
$(".message").html(JSON.stringify(json));
});
});
catalinscr sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1435 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
otmeek sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1436 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
// blink count twice
$('#count').removeClass('count-on');
$('#count').addClass('count-off');
var blink = setTimeout(blinkCount, 500);
// start game turns
nextTurn(0);
setTimeout(function(){
blinkCount()
},500);
otmeek sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:warning: otmeek already gave h4r1m4u points
otmeek sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:star: 21 | @alexgaudiosi | http://www.freecodecamp.com/alexgaudiosi
@h4r1m4u
looking at this:
http://stackoverflow.com/questions/12307064/responsive-css-for-phones-small-screens
i tried to use this code.
@media (max-width: 1200px) {
body {
padding-left: 50px;
padding-right: 50px;
color: #FFF;
}
}
@media (max-width: 480px) {
body {
padding-left: 5px;
padding-right: 5px;
text-align:center;
}
}
function blinkCount() {
$('#count').removeClass('count-off');
$('#count').addClass('count-on');
setTimeout(function() {
$('#count').removeClass('count-on');
$('#count').addClass('count-off');
setTimeout(function() {
$('#count').removeClass('count-off');
$('#count').addClass('count-on');
}, 500);
setTimeout(function() {
// start game turns
nextTurn(0);
}, 500);
}, 500);
}
// this would apply to ALL screens up to 1200px wide
@media (max-width: 1200px) {
body {
padding-left: 50px;
padding-right: 50px;
color: #FFF;
}
}
// this would apply to ALL screens up to 480px wide
@media (max-width: 480px) {
body {
padding-left: 5px;
padding-right: 5px;
text-align:center;
}
}
otmeek sends brownie points to @alexgaudiosi :sparkles: :thumbsup: :sparkles:
:warning: otmeek already gave alexgaudiosi points
max-width: 480px;
but it broke everything when in a larger size
robmo sends brownie points to @h4r1m4u and @otmeek and @robynsmith :sparkles: :thumbsup: :sparkles:
:star: 171 | @robynsmith | http://www.freecodecamp.com/robynsmith
:star: 1437 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
:star: 348 | @otmeek | http://www.freecodecamp.com/otmeek
@media only screen and (max-width: 480px) {
body {
padding-left: 5px;
padding-right: 5px;
text-align:center;
}
}
@RobMo The docs are pretty good:
https://secure.php.net/docs.php
https://secure.php.net/manual/en/
I found this post is pretty good:
https://www.reddit.com/r/PHP/comments/262469/what_is_the_best_way_to_start_learning_php/
It will setup a syllabus of what to learn - you can google stuff for specifics as well.
dhoover1 sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1438 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
@media only screen and (min-width: 481px) {
}
@media only screen and (min-width: 481px) and (max-width: 780px) {
}
dhoover1 sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:warning: dhoover1 already gave h4r1m4u points
while(t <= turn) {
setTimeout(AIbutton(allMoves[t-1]), 1000);
t++;
}
AIbutton(allMoves[0])
to execute first, then AIbutton(allMoves[1])
and so on and so on until t = turn
.para {
width: 950px;
margin: 0 auto;
}
@KacperPorembski One way to do it is
document.getElementById('idOfElement').style.css = ...
Example:
document.getElementById('bgc').style.backgroundColor = "#12C4FF";
ahzuxramsey sends brownie points to @tstusr441 :sparkles: :thumbsup: :sparkles:
:star: 245 | @tstusr441 | http://www.freecodecamp.com/tstusr441
ahzuxramsey sends brownie points to @tommygebru :sparkles: :thumbsup: :sparkles:
:star: 632 | @tommygebru | http://www.freecodecamp.com/tommygebru
kacperporembski sends brownie points to @tstusr441 :sparkles: :thumbsup: :sparkles:
:star: 246 | @tstusr441 | http://www.freecodecamp.com/tstusr441
recipe challenge
. i've seen semantic-ui has modals for that which is buggy at times. Could you suggest an easy way for a making a popup that blocks/blurs out the background etc? (other than the full manual implementation which im gonna make with overlays and z-indexes and else)
mikenaza sends brownie points to @urobert :sparkles: :thumbsup: :sparkles:
:star: 601 | @urobert | http://www.freecodecamp.com/urobert
I'm having difficulty making an app that gets weather information when a button is clicked. I think the problem might come from the fact that I've placed my getJSON inside a function, but I don't know how else to do it:
<form>
Enter Location:
<input type="text" placeholder="city, state" id="mycity">
<button type="button" id="getWeather">Get Weather</button>
</form>
type="button"
to the button. by default buttons without a type specified are submit buttons. by setting the type to button, your Get Weather button will no longer submit the form and reload the page
$( ".your-element" ).hover(
// this function determines what happens when the cursor rolls over the element
function() {
$( this ).addClass("bounce");
},
// this determines what happens when your cursor leaves the element
function() {
$( this ).removeClass( "bounce" );
}
);
minhazul-islam sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1439 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
minhazul-islam sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:warning: minhazul-islam already gave h4r1m4u points
blayman sends brownie points to @h4r1m4u :sparkles: :thumbsup: :sparkles:
:star: 1440 | @h4r1m4u | http://www.freecodecamp.com/h4r1m4u
otmeek sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star: 274 | @lumexralph | http://www.freecodecamp.com/lumexralph
zeemax sends brownie points to @omranabazid :sparkles: :thumbsup: :sparkles:
:star: 193 | @omranabazid | http://www.freecodecamp.com/omranabazid
XMLHttpRequest cannot load https://en.wikipedia.org/w/api.php?action=opensearch&search=zyz&limit=1&namespace=0&format=jsonp. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access.
https://crossorigin.me
dhcodes sends brownie points to @otmeek and @otmeek :sparkles: :thumbsup: :sparkles:
:star: 349 | @otmeek | http://www.freecodecamp.com/otmeek
:star: 349 | @otmeek | http://www.freecodecamp.com/otmeek
fuzyon sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star: 365 | @dhcodes | http://www.freecodecamp.com/dhcodes
var city = $('#city-input').val();
this is probably the issue
mbrad26 sends brownie points to @fuzyon :sparkles: :thumbsup: :sparkles:
:star: 180 | @fuzyon | http://www.freecodecamp.com/fuzyon
$.get("api.openweathermap.org/data/2.5/weather?lat=35&lon=139&APPID=c9d28aa45581e0938c09929d53c57a58", function(response) {
console.log(response);
})
bananahavana sends brownie points to @fuzyon :sparkles: :thumbsup: :sparkles:
:star: 181 | @fuzyon | http://www.freecodecamp.com/fuzyon
mbrad26 sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star: 366 | @dhcodes | http://www.freecodecamp.com/dhcodes
$.getJSON("api.openweathermap.org/data/2.5/weather?lat=35&lon=139&APPID=c9d28aa45581e0938c09929d53c57a58", function(response) {
console.log(response);
})
bananahavana sends brownie points to @mbrad26 :sparkles: :thumbsup: :sparkles:
:star: 279 | @mbrad26 | http://www.freecodecamp.com/mbrad26
bananahavana sends brownie points to @fuzyon and @mbrad26 :sparkles: :thumbsup: :sparkles:
:warning: bananahavana already gave mbrad26 points
:warning: bananahavana already gave fuzyon points
mbrad26 sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:warning: mbrad26 already gave dhcodes points
var jsonObject = [
{
"number": 1,
}
];
var obj = JSON.parse(jsonObject);
function generator(){
//var randomNumber = Math.floor((Math.random() * 10) + 1);
document.getElementById("inject").innerHTML = obj[0];
};
document.getElementById("quoteHere").textContent
$("#tweet").click(function(){
window.open("http://twitter.com/intent/tweet?text=" + document.getElementById("quoteHere").textContent , target="_blank", "width=800, height=600");
});
diver2026 sends brownie points to @sludge256 :sparkles: :thumbsup: :sparkles:
:star: 1565 | @sludge256 | http://www.freecodecamp.com/sludge256
reacorbett sends brownie points to @feitla :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for feitla
var latitude, longitude, weatherObject;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function displayPosition(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
$.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&APPID=c9d28aa45581e0938c09929d53c57a58", function(response) {
weatherObject = JSON.parse('response');
console.log(weatherObject);
}
)}
)};
reacorbett sends brownie points to @feitla :sparkles: :thumbsup: :sparkles:
:star: 30 | @feitla | http://www.freecodecamp.com/feitla
console.log(response);
bananahavana sends brownie points to @mutantspore :sparkles: :thumbsup: :sparkles:
:star: 1150 | @mutantspore | http://www.freecodecamp.com/mutantspore
var placeName = response.name
&callback=?
to your url