These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Nov 2017
Donnie
@Donnie-D
Nov 12 2017 00:03
@alpox but why does the following work
<!DOCTYPE html>
<html>
<body>

<p>Counting with a local variable.</p>

<button type="button" onclick="myFunction()">Count!</button>

<p id="demo">0</p>

<script>
var add=(function () {
    var counter = 0;
    return function () {return counter += 1;}
})();

function myFunction(){
    document.getElementById("demo").innerHTML = add();
}
</script>

</body>
</html>
alpox
@alpox
Nov 12 2017 00:06
@Donnie-D because now you invoke the function already and assign the return value of the call to add. Before, add was the function which you already called now itself.
Donnie
@Donnie-D
Nov 12 2017 00:09
@alpox but add self invoked itself before too. didnt it?
and when it self invokes itself, it creates a variable and declares a new function
lion18
@lion18
Nov 12 2017 04:20
Hi,
Hi
Can anyone tell me what's wrong in this code https://codepen.io/lion18/pen/yzrKQw that when I click on the temperature, it gets converted from Celsius to Farenheit once but doesn't respond after that.
Basically, it's just does it one time, doesn't get looped.
Isaiah Trembley
@IsaiahCT
Nov 12 2017 04:24
hey guys
what is going on with this code?
why wont it work
nm
Devin Miller
@edwin0258
Nov 12 2017 04:37
@lion18
On Line 47 it should be $("#cTemp").html(cTemp);
kha97
@kha97
Nov 12 2017 05:02
hey guys i am on the pomodorro clock project and everything is working except for the reset button i think clearInterval isnt working everytime i cliked the reset button it reset for a sec and than the clock keeps counting down var code = "formatted"; function ResetClock(){
clearInterval(timeInterval);
console.log("pppp");
bminutes.innerHTML="25";
bseconds.innerHTML="00";
work_minutes=25;
break_minutes=5;
}
lion18
@lion18
Nov 12 2017 05:04
@edwin0258 Thanks
CamperBot
@camperbot
Nov 12 2017 05:04
lion18 sends brownie points to @edwin0258 :sparkles: :thumbsup: :sparkles:
:cookie: 810 | @edwin0258 |http://www.freecodecamp.com/edwin0258
Devin Miller
@edwin0258
Nov 12 2017 05:05
@kha97 Do you have a link to a codepen?
Devin Miller
@edwin0258
Nov 12 2017 05:10
@kha97 If you do this it should work (Around line 59)
var timeInterval
  function updateClock(){

        timeInterval = setInterval(function(){
kha97
@kha97
Nov 12 2017 05:11
@edwin0258 but I already declared timeInterval at the very beginning
Devin Miller
@edwin0258
Nov 12 2017 05:12
@kha97 Oh, then you can just do (Take off the var in updateClock)
function updateClock(){

        timeInterval = setInterval(function(){
kha97
@kha97
Nov 12 2017 05:14
@edwin0258 Thanks so much I spent ages looking at it hhhh
CamperBot
@camperbot
Nov 12 2017 05:14
kha97 sends brownie points to @edwin0258 :sparkles: :thumbsup: :sparkles:
:cookie: 811 | @edwin0258 |http://www.freecodecamp.com/edwin0258
Devin Miller
@edwin0258
Nov 12 2017 05:14
:) :thumbsup:
kha97
@kha97
Nov 12 2017 05:17
@edwin0258 sorry but the problem is still persistant :worried:
Devin Miller
@edwin0258
Nov 12 2017 05:18
What do you mean?
kha97
@kha97
Nov 12 2017 05:19
@edwin0258 same problem when I click on the reset button it displays the original 25:00 and then returns to the countdown
Devin Miller
@edwin0258
Nov 12 2017 05:21
@kha97 Strange, it's working for me.
kha97
@kha97
Nov 12 2017 05:23
@edwin0258 interesting,I think the problem has to do with clearInterval because the clock doesnt stop
Devin Miller
@edwin0258
Nov 12 2017 05:23
@kha97 Are you using manual run on codepen? Maybe it needs to be run again with new code.
And what browser are you using?
kha97
@kha97
Nov 12 2017 05:24
@edwin0258 manual run ? and chrome
Devin Miller
@edwin0258
Nov 12 2017 05:25
There is a button that says run in header of codepen. @kha97
kha97
@kha97
Nov 12 2017 05:27
@edwin0258 I opened my link in incognito mode and it worked ! but on my own project page it doesnt seem to work
Devin Miller
@edwin0258
Nov 12 2017 05:27
@kha97 Try reloading.
kha97
@kha97
Nov 12 2017 05:28
@edwin0258 it work now Thanks again mate
CamperBot
@camperbot
Nov 12 2017 05:28
kha97 sends brownie points to @edwin0258 :sparkles: :thumbsup: :sparkles:
api offline
Devin Miller
@edwin0258
Nov 12 2017 05:29
@kha97 One other thing. I noticed when I press to increment time it doesn't stop timer, maybe trying adding ResetClock to these events. For example:
$("#addB").click(function(){
    ResetClock()
sr3k4nth
@sr3k4nth
Nov 12 2017 05:55
any angular guys ?
what does angular.element($('.div')).scope() do ?
Abdurrahman Al Hanif
@unip
Nov 12 2017 14:54

Hello everyone. I'm in wikipedia viewer challenge. I can't get my search box input value to then I use it as keyword/ search term. Here is my pen: https://codepen.io/unip/pen/mqPxPe?editors=1010

Any help would be appreciated.

Also, I have error message in my chrome console like this:
Failed to load https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
Abdurrahman Al Hanif
@unip
Nov 12 2017 15:01
from this error message, you can see the API link don't have keyword on search= from keyword variable I made at line 3, and that's the problem.
Christopher Brown
@ChrisBrownie55
Nov 12 2017 17:07
@unip You need to get the keyword once they've typed and searched, not before
@unip when you press enter on the search bar it should run keyword = $('#searchBox').val()
Uriel Guzmán
@Burinson
Nov 12 2017 19:16
function checkCashRegister(price, cash, cid) {
  var currency = {
   "PENNY": 0.01, 
   "NICKEL": 0.05,
   "DIME": 0.10, 
   "QUARTER": 0.25, 
   "ONE": 1.00, 
   "FIVE": 5.00, 
   "TEN": 10.00, 
   "TWENTY": 20.00, 
   "ONE HUNDRED": 100.00
  };
  var currArr = [];
  for (var c in currency) {
    currArr.push(currency[c]);
    // Push all the currency values.
  }

  var cidArr = [];
 for (var i in cid) {
   for (var x in cid[i]);
  cidArr.push(cid[i][x]);
   // Push all the cash in drawer values.

 }

  var result = [];
  var howMany = currArr.concat(cidArr);
  for (var z = 9; z < howMany.length; z++) {
    result.push(howMany[z] / howMany[z-9]);
    // Push how many of each currency the cash in drawer has.   
  }

   var difference = cash - price; // Change.

  var keys = Object.keys(currency); // Names of currency
var backwards = keys.reverse(); // Greater to smaller

  var value;
for (var y = 0; y < backwards.length; y++) {

  var valuesReversed = currency[backwards[y]];

   if (difference % valuesReversed !== difference) { 
     // Return the greatest divisible number of the change.
       value = valuesReversed; 
     break;
    } 
}

  var name;

  for (var v in currency) {
    if (currency[v] === value) {
      name = v;
      // Name of the currency to give back.
    }
  }

  var have = "";
  for (var h in cid) {
    if (cid[h][0] === name) {
      have = cid[h][1];
      // How much money of that currency type is in the drawer.
    }    
  }
 var change;
  var give;
  var newDiff;
  if (difference > have) {
    // If there is more change than currency of that type in the register...
    newDiff = difference - have;
    // Difference between change and how much we have.
    change = difference - newDiff;
    // Return the maximum amount of money for that currency type.   
  }  

  return [[name, change]];

} 

checkCashRegister(3.26, 100.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);
How can I repeat this function until there is no more change left?
FlashHero
@FlashHero
Nov 12 2017 20:20
@Burinson maybe use a while loop and subtract the values each time until there's no change left. I didn't go through your code but that's the general idea if your code follows the rule of subtracting values
Uriel Guzmán
@Burinson
Nov 12 2017 22:29
@FlashHero Thanks, I made consecutive if statements
CamperBot
@camperbot
Nov 12 2017 22:29
burinson sends brownie points to @flashhero :sparkles: :thumbsup: :sparkles:
:cookie: 215 | @flashhero |http://www.freecodecamp.com/flashhero
Conor Murphy
@cmurphy580
Nov 12 2017 22:58
@korzo thank you realized that long after this
CamperBot
@camperbot
Nov 12 2017 22:58
cmurphy580 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 764 | @korzo |http://www.freecodecamp.com/korzo
Conor Murphy
@cmurphy580
Nov 12 2017 22:59
does anyone know of a click toss add on/feature for scroll bars? Either where i can find the code or a script tag to add it into my website>