Any experts out there willing to do a quick code review of a small combat system I made? It works fine I just feel like there must be a much better way of going about it.
function load(){
var nets = require('nets')
nets({
url: 'https://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=jsonp&lang=en&jsonp=?',
json : true
},
function(quot){
$("p").text(quot.quoteText);
});
}
var Dialogue = (typeof exports !== 'undefined') ? exports : {};
@Bazill03 Oh, and you need to change that:
Dialogue.load = function(actor, file){
console.log(file);
var fs = require('fs');
fs.readFile(file, function (err, data) {
if (err) {
throw err;
}
Dialogue.parse(actor, data.toString());
});
}
Because var fs = require('fs')
is a node module for loading files. You can either use xmlhttprequest, or jquery, or don't even load a file, but a string instead
const sounds = { witheredIntroSound: new Audio('...'), ...}
. Same for the weapons. Also, you can take a look at const if you already use let ;)bazill03 sends brownie points to @otto-aa :sparkles: :thumbsup: :sparkles:
:cookie: 391 | @otto-aa |http://www.freecodecamp.org/otto-aa
require
is a function used in node.js (basically an extended version of javascript for the backend) so you can't use it in browsers. To get what you want, you probably should take a look at this stackoverflow question: https://stackoverflow.com/questions/21715620/using-jsonp-to-get-json-data-from-another-server
1532j0004kg sends brownie points to @otto-aa :sparkles: :thumbsup: :sparkles:
:cookie: 392 | @otto-aa |http://www.freecodecamp.org/otto-aa
request = 'myString'
and define it yourself
Cannot find module 'nets'
but I am not familiar with nodejs so maybe I forgot something
document
/window
/body
and therefore also no <p>
where you could insert the quote. So no, it won't work
ericzomar sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 2067 | @heroiczero |http://www.freecodecamp.org/heroiczero
apm is bundled and installed automatically with Atom. You can run the Atom > Install Shell Commands menu option to install it again if you aren't able to run it from a terminal (macOS only).
.wrap { top: 50%; }
? you are setting it to 72%
which pushes it down
Full Page
view to see it in the middle
erick425 sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 447 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
apm install atom-html-preview
into your console. But I don't use Atom, so I don't know
.wrap { top: 50%; }
erick425 sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
<div class="row no-gutters">
<div class="col-md-10 no-gutters">
<div class="col-md-4">
<button class="reg"> <p class="btn"> 1 </p></button>
</div>
<div class="col-md-4 no-gutters">
<button class="reg"> <p class="btn"> 2 </p></button>
</div>
<div class="col-md-4">
<button class="reg"> <p class="btn"> 3 </p></button>
</div>
<div class="col-md-12">
<div class="col-md-8">
<button class="reg btn-block"> <p class="btn"> 0 </p></button>
</div>
<div class="col-md-4">
<button class="reg btn-default"> <p class="btn"> . </p></button>
</div>
</div>
</div>
<div class="col-md-2">
<button class="reg"> <p class="btn"> = </p></button>
</div>
</div>
position: relative;
to .scale
, so the search positions itself relative to the image and not the body
position: relative;
and test
margin: 35px auto;
. Which is pushing everything to the left.
auto
part centers it in the middle. The 35px
is top and bottom margin
transform: translate(-50%, -50%)
?
and does the pen I sent you works?
@tundeiness
setInterval(function(), 5000)
that should delay for 5 seconds before running the first time, correct?
function loseTimer(combination) {
$('#counter').val('! !');
loseAudio.play();
i = 0;
patternInditcator(combination);
}
function gameStart(combo, time) {
var combination = combo || [];
var next = callNext();
var i = 0; //increment
var score = $('#counter').val();
var click = false; //var to check game time out
var dTime = time || 5000;
var repeatDelay = null;
combination.push(next);
console.log(combination);
//interval to space out pattern activation
patternInditcator(combination);
//end-of-game timeout due to inactivity
if (!click) {
setTimeout(function() {
repeatDelay = setInterval(loseTimer(combination), dTime);
}, dTime);
}
...
The loseAudio
plays immediately...
setTimeout
which has been removed...
loseTimer
to run periodically, you need to pass the function into setInterval: repeatDelay = setInterval(loseTimer, dTime);
repeatDelay = setInterval(loseTimer(combination), dTime);
?
setInterval(loseTimer(combination), dTime);
this will call loseTimer(combination)
and return the result (=> setInterval(undefined, dTime);
) instead of passing the function as argument
rscales02 sends brownie points to @masd925 and @otto-aa and @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 393 | @otto-aa |http://www.freecodecamp.org/otto-aa
:cookie: 448 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
:star2: 4577 | @masd925 |http://www.freecodecamp.org/masd925
setInterval(loseTimer, dTime)
to pass the function without parameters or setInterval(function() {loseTimer(combination);}, dTime)
to pass it the combinationsetInterval(() => loesTimer(combination), dTime)
)
rscales02 sends brownie points to @otto-aa :sparkles: :thumbsup: :sparkles:
col-md-2
etc
col-2-md
hi,
For the challenge seek and destroy, I wrote this code
function destroyer(arr) {
var argumentsArr = Array.from(arguments);
var argLength = argumentsArr.length;
var array = arr;
var length = array.length;
for(i=0;i<length;i++){
if(argumentsArr.indexOf(array[i])!=-1){
delete array[i];
}
}
return array;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
and the result is[1, null, null, 1, null, null]
so what should I change to not get null, and completely remove the element?
col-xs-2
md
refers to medium sized screens
display: flex;
function updateInventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
// Check if arr1 one has value of arr2.
var updatedArr = arr1;
var flatArr1 = [];
// Makes a flat array of the current inventory.
for (var h = 0; h < arr1.length; h++) {
flatArr1.push(arr1[h][1]);
}
console.log(flatArr1);
// Compares every newInventory article with every one in the current Inventory array.
for (var j = 0; j < arr2.length; j++) {
var newItem = arr2[j][1];
console.log(newItem);
for (var i = 0; i < arr1.length; i++) {
if (flatArr1.indexOf(newItem)=== -1 && updatedArr.indexOf(newItem)===-1){
updatedArr.push(arr2[j]);
console.log('if');
}
else if (arr1[i][1] === newItem) {
updatedArr[i][0] = arr1[i][0] + arr2[j][0];
console.log(arr2);
console.log('if else');
}
else {
console.log('do nothing');
}
}
}
console.log(updatedArr);
}
// Example inventory lists
var curInv = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];
var newInv = [
[2, "Hair Pin"],
[3, "Half-Eaten Apple"],
[67, "Bowling Ball"],
[7, "Toothpaste"]
];
updateInventory(curInv, newInv);
var updatedArr = arr1;
for (var i = 0; i < arr1.length; i++) {
if (flatArr1.indexOf(newItem)=== -1 && updatedArr.indexOf(newItem)===-1){
updatedArr.push(arr2[j]); ///<-- u keep increasing the array u iterating (arr1) causing infinite loop
michielhuijse sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3714 | @moigithub |http://www.freecodecamp.org/moigithub
<nav>
tag in this page as u don't have any navigation in there. a <header>
tag will be more semantic in this case.
chrisandsuch sends brownie points to @kbaig and @rajanikantdeshmukh and @sorinr and @mot01 :sparkles: :thumbsup: :sparkles:
:cookie: 299 | @rajanikantdeshmukh |http://www.freecodecamp.org/rajanikantdeshmukh
:cookie: 912 | @mot01 |http://www.freecodecamp.org/mot01
:cookie: 434 | @kbaig |http://www.freecodecamp.org/kbaig
:star2: 1361 | @sorinr |http://www.freecodecamp.org/sorinr
anything === value1 ? value2 : value1
if this ? do this : otherwise, do this
const a = 1 < 2 ? 'hello' : 'world'; // 'hello'
rajanikantdeshmukh sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 436 | @kbaig |http://www.freecodecamp.org/kbaig
// return the lesser of two values
function (a, b) {
return a < b ? a : b;
}
sharkantropo sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 437 | @kbaig |http://www.freecodecamp.org/kbaig
id = ' reset'
to id = 'reset'
benjmhart sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 440 | @kbaig |http://www.freecodecamp.org/kbaig
// Play audio
var wav = 'https://s3.amazonaws.com/freecodecamp/simonSound4.mp3';
var audio = new Audio(wav);
audio.play();
benjmhart sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3516 | @khaduch |http://www.freecodecamp.org/khaduch
benjmhart sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles: