I'm trying to figure out what to do with this code here as to why my calculator doesn't seem to calculate (and total) anything.
var operators = ["/", "*", "-", "+"];
var decimalAdded = false;
for (var i = 0; i < operators.length; i++) {
$('.division').onclick();
}
Can anyone help me out if they've done this project before?
@Swoozeki I changed it to this instead.
var operators = ["/", "*", "-", "+"];
var decimalAdded = false;
for (var i = 0; i < operators.length; i++) {
$('.op').onclick();
}
Now how do I change this again?
.onclick();
method. I guess it didn't work out. Now here's what I did.var operators = ["/", "*", "-", "+"];
var decimalAdded = false;
for (var i = 0; i < operators.length; i++) {
$('.op').click(operators);
}
$(".button").click(function(){
document.write("You just clicked a button");
});
What this code does is, upon clicking the anything with the class button, the text "You just clicked a button" appears
@Swoozeki But the document.write();
didn't work with my calculator. I tried dividing a number and it went to a different page. I'm trying to figure something out in which I can write a code using all operators instead of one each to make it simple.
$('.op').click(function() {
document.write('/');
});
I was thinking of the math objects as mentioned in w3schools.com, for example but it didn't work.
var block="";
$(".button").click(function(){)
var block="";
$(".button").click(function(){
block+=this.innerHTML;
});
$(".button").click(function(){
if(this.id==="number-button"){
//display this.id.innerHTML;
}
});
$(".button").click(function(){
if(this.id==="number-button"){
$('#inputSec').text(this.id.innerHTML);
}
});
in your case...
class
for my number button.$('button').click(function() {
if (this.class === "numBut") {
//display this.id.innerHTML;
$('#inputSec').text(this.class.innerHTML);
}
});
alcatrats sends brownie points to @jondcoleman :sparkles: :thumbsup: :sparkles:
:star: 486 | @jondcoleman | http://www.freecodecamp.com/jondcoleman
function getdesc() {
for (j=0; j<10;j++) {
var title2=($("#title"+(j+1)).html())
$.getJSON("https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exsentences=1&formatversion=2&explaintext=&titles="+title2+"&callback=?",function(ex) {
$("#description"+(j+1)).text(ex["query"]["pages"][0]["extract"]);
});
}
}
Whereas title2 is returning the correct values of the title of what I'm adding a description to if I console.log(title2)
i
when the getJSON is initiated. so wrap the getJSON in another function that takes the iterator as an argument.function getdesc() {
getData(num) {
$.getJSON(yourURL, function(ex) {
$("#description"+(j+1)).text(ex["query"]["pages"][0]["extract"]);
});
}
for (j=0; j<10;j++) {
var title2=($("#title"+(j+1)).html())
getData(i);
}
}
keccakec sends brownie points to @mattyamamoto :sparkles: :thumbsup: :sparkles:
:star: 902 | @mattyamamoto | http://www.freecodecamp.com/mattyamamoto
getPlayerInput
method is run that you then run listenForInput
which then adds a click binding to your btns. So each time you add another binding. Which means one user click will result in multiple executions of the click function.
.off() in there
... so let me look deeper.
zaclem01 sends brownie points to @mattyamamoto :sparkles: :thumbsup: :sparkles:
playerTurn
for example, then in your .getPlayerInput()
method you could just set playerTurn = T
and that would let the click events do something. Does that make sense?
:star: 903 | @mattyamamoto | http://www.freecodecamp.com/mattyamamoto
playerTurn
to true once the adding and displaying is done?
playerTurn
is just the gate keeper to some chunck of code in the click function. so yes, if playerTurn
is true then light up the buttons when the user clicks and compare the button press to the expected sequence. whenever the player's turn is done, just set the boolean back to false and their clicks won't do anything anymore.
tommygebru sends brownie points to @mattyamamoto :sparkles: :thumbsup: :sparkles:
:star: 904 | @mattyamamoto | http://www.freecodecamp.com/mattyamamoto
tommygebru sends brownie points to @mattyamamoto :sparkles: :thumbsup: :sparkles:
:warning: tommygebru already gave mattyamamoto points
* {border: 1px dashed red}
to your css, then one by one start styling your divs, adding outer divs as necessary.
@MattYamamoto haha design can be so conflicting sometimes wouldn't you agree
try 17vw... that's about as big as you can go without a horizontal scroll at small screen sizes. I stay stick with this one. visually it looks good, so your vision is good.
.enlarge
class a height of 100vh
, is that what your after? And my red border was just a suggestion to visualize what's there, not to keep for production...unless of course you like it.
tommygebru sends brownie points to @mattyamamoto :sparkles: :thumbsup: :sparkles:
:warning: tommygebru already gave mattyamamoto points
var operators = ["/", "*", "-", "+"];
var decimalAdded = false;
var block = "";
$('button').click(function() {
if (this.class === "numBut") {
// display this.id.innerHTML;
$('#inputSec').text(this.class.innerHTML);
}
});
@eyohansa Now how do I add those things you mentioned? I've been trying to figure this out but I can't calculate the numbers. I can enter numbers, clear them, and enter them again but I still can't calculate and total the numbers.
var operators = ["/", "*", "-", "+"];
var decimalAdded = false;
var block = "";
$('button').click(function() {
if (this.class === "numBut") {
// display this.id.innerHTML;
$('#inputSec').text(this.class.innerHTML);
} else if (operators.class === "op") {
var result = operators.test(/[0-9]\d/);
} else {
return decimalAdded = false;
}
});
Is there something wrong with this code?
$(.className)
to select those buttons.
$(".op").click(function() {
var op = $(this).text(); // This will get the text content of the op buttons, such as +, -, etc.
switch(op) {
case "+":
result = storedNum1 + storedNum2;
// other cases
}
$("#inputSec").text(result);
}
function operators(block, decimalAdded) {
$('.op').click(function() {
var op = $(this).text();
switch (op) {
case "+":
result = storedNum1 + storedNum2;
break;
case "-":
result = storedNum1 - storedNum2;
break;
case "*":
result = storedNum1 * storedNum2;
break;
case "/":
result = storedNum1 / storedNum2;
break;
default:
console.log("=");
}
$('#inputSec').text(result);
});
}
function total() {
console.log('the result of your equation is: ' + math.eval(input));
$('#inputSec').text(math.eval(input));
}
If you're using that, then you can do something like
$(".op").click(function() {
var input = $("#inputSec").text();
input += $(this).text();
$("#inputSec").text(input);
}
and add the total function from @atan77 and it should be done.
cannelflow sends brownie points to @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1318 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
The below code iam using to fetch data from javascript object(JSON)
var obj = {
date: " 2012-10-18 16:58:35.104576",
data: [
{
title: "The Princess Bride",
rating: "PG",
length: 128,
stars: [
"Gary Elwes",
"Robin Wright",
"Christopher Guest"
]
},
{
title: "This is Spinal Tap",
rating: "R",
length: 105,
stars: [
"Christopher Guest",
"Michael McKean",
"Harry Shearer"
]}
]
};
$.each(obj.data[0] , function(ke , va ){
alert('key'+ke);
});
$.each(obj.data , function(key , value){ //
$.each(value.stars , function(k , v ){
alert(k+':'+v);
});
});
Here i am looping obj.data twice is it necessary, because i want to echo the key in obj.data only once and values in obj.data multiple times
ishanshukla97 sends brownie points to @mutantspore :sparkles: :thumbsup: :sparkles:
:star: 1078 | @mutantspore | http://www.freecodecamp.com/mutantspore
col-md-number
, or set a min-width
of li
element
mocha3012 sends brownie points to @urobert :sparkles: :thumbsup: :sparkles:
:star: 550 | @urobert | http://www.freecodecamp.com/urobert
overflow: auto;
the scrollbar goes away but there is still a white space there
bgogurt sends brownie points to @swoozeki :sparkles: :thumbsup: :sparkles:
:star: 277 | @swoozeki | http://www.freecodecamp.com/swoozeki
jlouiss sends brownie points to @ankitrn :sparkles: :thumbsup: :sparkles:
:star: 255 | @ankitrn | http://www.freecodecamp.com/ankitrn
durablemicron sends brownie points to @bgogurt :sparkles: :thumbsup: :sparkles:
:star: 253 | @bgogurt | http://www.freecodecamp.com/bgogurt
smikeyr sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 402 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
smikeyr sends brownie points to @codybousc :sparkles: :thumbsup: :sparkles:
:star: 314 | @codybousc | http://www.freecodecamp.com/codybousc
$("#decimal").click(function(){
number = "";
var numOfDecs = "0";
for (i=0,i<number.length;i++){
if (number.charAt("i") = ".") {
(parseInt(numOfDecs,10) + 1).toString(10);
}
if (numOfDecs === "0"){
number.append(".");
}
totaldiv.text(number);
textNumlength(number);
};
});
$("#decimal").click(function(){
number = "";
var numOfDecs = "0";
for (i=0,i<number.length,i++) {
if (number.charAt("i") = ".") {
numOfDecs = (parseInt(numOfDecs,10) + 1).toString(10);
}
};
if (numOfDecs === "0") {
number.append(".");
totaldiv.text(number);
testNumlength(number);
}
});
function drawer(price, cash, cid) {
var change = cash - price;
console.log(change);
while(change >= 100 && cid[8][1] >= 100) {
change-= 100;
cid[8][1]-= 100;
console.log("Subtracted One Hundred");
}
while(change >= 20 && cid[7][1] >= 20) {
change-= 20;
cid[7][1]-= 20;
console.log("Subtracted Twenty");
}
while(change >= 10 && cid[6][1] >= 10) {
change-= 10;
cid[6][1]-= 10;
console.log("Subtracted Ten Dollars");
}
while(change >= 5 && cid[5][1] >= 5) {
change-= 5;
cid[5][1]-= 5;
console.log("Subtracted One Five Dollars");
}
while(change >= 1 && cid[4][1] >= 1) {
change-= 1;
cid[4][1]-= 1
console.log("Subtracted One Dollar");
}
while(change >= .25 && cid[3][1] >= .25) {
change-= .25;
cid[3][1]-= .25;
console.log("Subtracted 25 Cents");
}
while(change >= .10 && cid[2][1] >= .10) {
change-= .10;
cid[2][1]-= .1;
console.log("Subtracted 10 Cents");
}
while(change >= .05 && cid[1][1] >= .05) {
change-= .05;
cid[1][1]-= .05;
console.log("Subtracted 5 Cents");
}
while(change >= .00 && cid[0][1] >= .00) {
change-= .01;
cid[0][1]-= .01;
console.log("Subtracted 1 Cent");
console.log(change);
}
for(var i = 0; i < cid.length; i++) {
if(cid[i][1] == 0 && change == 0) {
console.log("Closed");
}
else if(cid[i][1] < 0) {
console.log("Insufficient Funds");
console.log(cid[i][0]);
}
}
console.log(cid);
console.log(change);
}
drawer(19.50, 20.00, [["PENNY", 0.50], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
</head>
<body>
<a>
<div id="project">
<div class="project-picture project_1_picture">
<div class="overlay">
</div>
<div class="fire"><i class="fa fa-fire"></i></div>
</div>
<div class="project-name"></div>
</div>
</a>
</body>
<style>
#project {
position: relative;
display: inline-block;
height: 230px;
width: 250px;
border: 2px silver solid;
border-radius: 2px;
margin: 3px 8px 30px 8px;
box-shadow: 0 1px 2px rgba(0,0,0,0.15);
transition: all 0.3s ease-in-out;
}
/* Create hidden pseudo-element */
/* include the shadow for the end state */
#project::after {
content: '';
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 230px;
width: 250px;
opacity: 0;
border-radius: 2px;
box-shadow: 0 0 50px rgba(0,0,0,0.9);
transition: opacity 0.3s ease-in-out;
}
/* Scale up the box */
#project:hover {
transform: scale(1.03, 1.03);
}
/* Fade in the pseudo-element with the bigger shadow */
#project:hover::after {
opacity: 1;
}
.project-picture {
diplay: block;
height: 150px;
width: 250px;
border-radius: 2px 2px 0px 0px;
background-color: blue;
opacity: .9;
}
.overlay {
height: 150px;
width: 250px;
background-color: none;
opacity: .7;
transition: background-color 0.5s ease;
}
.project_1_picture {
background-color: blue;
background-size: cover;
}
.project-name {
diplay: block;
width: 250px;
height: 80px;
border-radius: 0px 0px 2px 2px;
background-color: black;
opacity: .9;
}
.project-picture:hover .overlay{background-color: black}
.fire{
position: absolute;
display:block;
opacity: 0;
top:36px;
width:40px;
margin:0 auto;
left:0px;
right:0px;
z-index:100;
font-size: 45px;
color: white;
transition: opacity 0.5s ease;
}
.project-picture:hover .fire{opacity:1}
</style>
</html>
position:fixed;
on my container disables my buttons within ?
a-d-collins sends brownie points to @djcase001 :sparkles: :thumbsup: :sparkles:
:star: 135 | @djcase001 | http://www.freecodecamp.com/djcase001
position:fixed;
of the container. it acts like disable=true, in the meaning that they can't be clicked and no hover effect (otherwise working) is not displayed. The buttons should not do anything in particular as they are not locked to event handlers yet.
z-index:1;
on container . But thanks !
urobert sends brownie points to @unlimiworks :sparkles: :thumbsup: :sparkles:
:star: 286 | @unlimiworks | http://www.freecodecamp.com/unlimiworks
http://codepen.io/ankitrn/pen/GoMwEo
hey guys, just finished my pomodoro clock (hopefully there aren't any errors lol) what do you think?
ankitrn sends brownie points to @jessiw :sparkles: :thumbsup: :sparkles:
:star: 404 | @jessiw | http://www.freecodecamp.com/jessiw
unlimiworks sends brownie points to @arkine :sparkles: :thumbsup: :sparkles:
:star: 32 | @arkine | http://www.freecodecamp.com/arkine
jessiw sends brownie points to @unlimiworks :sparkles: :thumbsup: :sparkles:
:star: 287 | @unlimiworks | http://www.freecodecamp.com/unlimiworks
codybousc sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1117 | @blauelf | http://www.freecodecamp.com/blauelf
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
data._links.self
__links contains api end points, data.url
or data.streams.channel.url
danstockham sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 358 | @jnmorse | http://www.freecodecamp.com/jnmorse
var i
, it's like the last thing I need to complete my pomodoro clock and I've worked all day trying to figure it out! To make it easy to view, I've put it in its own pen :)var i
in javascript so I can use it to initialize my clock. The clock will start at 30 regardless of the function<div id="sessionValue">30</div>
i
to pull the value from sessionValue
element?
var i = parseInt(document.getElementById('console-log').innerHTML);
rusticman sends brownie points to @jondcoleman :sparkles: :thumbsup: :sparkles:
:star: 489 | @jondcoleman | http://www.freecodecamp.com/jondcoleman
var i = parseInt(document.getElementById('sessionValue').innerHTML);
i
for instance)
var sessionTime = i * 60;
is called when the page loads
i
(which is happening correctly)
sessionTime
will never update
startPause()
with sessionTime = i * 60
i
for setting the value
sessionTime
i
quotepool
... remember JS is casesensitive.. should be quotePool
(as u have declared above)$(document).ready(function() {
so it wont find.. out of scope...$(document).ready(function() {
sean9 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
$(document).ready(function() {
var quotePool = ["You live and you learn", "I'm always hungry for knowledge", "Food is life"];
var authorPool = ["Chubaka", "Henry", "Elise"];
var quote1, quote2, quote3 = "";
$('#newquote').on('click', myFunction);
function myFunction() {
var rannum = Math.floor(Math.random() * quotePool.length);
quote = quotePool[rannum] + ", " + authorPool[rannum];
$("#text").text(quote);
}
});
:star: 498 | @moigithub | http://www.freecodecamp.com/moigithub
sean9 sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 359 | @jnmorse | http://www.freecodecamp.com/jnmorse
I'm having difficulty getting my calculator to calculate, using operations, and total the numbers that I'm being impatient here.
var operators = ["/", "*", "-", "+"];
var decimalAdded = false;
var block = "";
$(".op").click(function() {
var input = $("#inputSec").text();
input += $(this).text();
$("#inputSec").text(input);
function total() {
console.log('the result of your equation is: ' + math.eval(input));
$('#inputSec').text(math.eval(input));
}
});
http://codepen.io/lisaramos/pen/MKBmgm
Can anyone help me out please?
return $("#twitter").attr("href", "https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=\"" + quote + " " + author + "\"");
if you change that line it should work better, and you may which to add target="_blank"
to your link in the html
target="_blank"
. After checking thepage with developer tools, i understand why it doesn't redirect properly (mainly because of codepen's page structure)unlimiworks sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 360 | @jnmorse | http://www.freecodecamp.com/jnmorse
clarkarnold sends brownie points to @alexanderkopke :sparkles: :thumbsup: :sparkles:
:star: 458 | @alexanderkopke | http://www.freecodecamp.com/alexanderkopke
var hour = (theDate.getHours().length > 1) ? theDate.getHours() : ('0' + theDate.getHours());
theDate.getHours() > 9
not length
m1kep sends brownie points to @jnmorse :sparkles: :thumbsup: :sparkles:
:star: 361 | @jnmorse | http://www.freecodecamp.com/jnmorse
console.log("Starting")
function getDateAndTime() {
// Statement ? true : false
var theDate = new Date();
var month = theDate.getMonth() > 9 ? theDate.getMonth() : '0' + theDate.getMonth();
var day = theDate.getDay() > 9 ? theDate.getDay() : '0' + theDate.getDay();
var hour = theDate.getHours() > 9 ? theDate.getHours() : '0' + theDate.getHours();
var min = theDate.getMinutes() > 9 ? theDate.getMinutes() : '0' + theDate.getMinutes();
return (theDate.getYear() + "-" + month + "-" + day + " " + hour + ":" + min);
}
console.log(getDateAndTime());
tommygebru sends brownie points to @jnmorse and @m1kep :sparkles: :thumbsup: :sparkles:
:star: 281 | @m1kep | http://www.freecodecamp.com/m1kep
:star: 362 | @jnmorse | http://www.freecodecamp.com/jnmorse
:star: 490 | @jondcoleman | http://www.freecodecamp.com/jondcoleman
aaronkazah sends brownie points to @jondcoleman :sparkles: :thumbsup: :sparkles: