var counter = 0;
var a = "#";
var counterForSlice = -7
while(counter < 12){
if(a.length <=7){
console.log(a);
a+="#";
}else{
var res = a.slice(counterForSlice);
console.log(res);
counterForSlice++;
}
counter++
}
well needs a bit of adjusting
koderkid1936 sends brownie points to @heinoustugboat :sparkles: :thumbsup: :sparkles:
render()
instead of render: function()
vikrantsingh13 sends brownie points to @sjames1958gm and @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @relentless-coder |http://www.freecodecamp.org/relentless-coder
:star2: 8857 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
this
context?
no you are not. The this
context of the callback is in a different context... you need to bind it to have an access inside the callback...
also setState
is a function: this.setState()
vikrantsingh13 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1125 | @marmiz |http://www.freecodecamp.org/marmiz
@VikrantSingh13 personal suggestion: start using ES6 syntax, makes everything easier.
instead of manually binding, for example you can use arrow function that does not bind the context.
addMarkup = (e) => this.setState({...})
setState
accept also a callback function:
setState(updater[, callback])
So you could call your markup function after setState is done updating the values.
hello guys im doin my tictactoe but on this part of the code is not working
function checkGame() {
//loops thru the winCombo array of arrays
for (var i=0; i<winCombo.length; i++) {
for (var j=0; j<winCombo[i].length; j++) {
//takes the values or text of the cells
var uno = document.getElementById(winCombo[i][0]).textContent;
var dos = document.getElementById(winCombo[i][1]).textContent;
var tres = document.getElementById(winCombo[i][2]).textContent;
//if theres no text on each cells
if (uno === '' && dos === '' && tres === '') {
break;
}
//checks if the variables have the same text value
else if (uno === dos && uno === tres) {
//if true remove the eventlistener then alart a winner
console.log('this will show if the condtion is true but loop is not working');
for(var c=0; c<cells.length; c++)
{
cells[c].removeEventListener('click', function(){
alert('shit!!!!')
});
}
}
}
}
}
but the console.log is show and the for loop to remove the event is not working.
heres the pen https://codepen.io/artoo/pen/Zvomxr
Send Action Data to the store (Redux FCC Beta)
const ADD_NOTE = 'ADD_NOTE';
const notesReducer = (state = 'Initial State', action) => {
switch(action.type) {
// change code below this line
case ADD_NOTE:
return action.text
// change code above this line
default:
return state;
}
};
const addNoteText = (note) => {
// change code below this line
type:ADD_NOTE,
text:note
// change code above this line
};
const store = Redux.createStore(notesReducer);
console.log(store.getState());
store.dispatch(addNoteText('Hello!'));
console.log(store.getState());
when i check the console i get the error saying unexpected token near text:note (addnoteText function)
no objective gets ticked
React: Add Event Listeners
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
message: ''
};
this.handleEnter = this.handleEnter.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
}
// change code below this line
componentDidMount() {
document.addEventListener('keypress', this.handleKeyPress);
}
componentWillUnmount() {
document.removeEventListener('keypress', this.handleKeyPress);
}
// change code above this line
handleEnter() {
this.setState({
message: this.state.message + 'You pressed the enter key! '
});
}
handleKeyPress(event) {
if (event.keyCode === 13) {
this.handleEnter();
}
}
render() {
return (
<div>
<h1>{this.state.message}</h1>
</div>
);
}
};
keydown
event, not a keypress
ostefani sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1127 | @marmiz |http://www.freecodecamp.org/marmiz
primuscovenant sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 2137 | @heroiczero |http://www.freecodecamp.org/heroiczero
```<html lang="de">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="style/bootstrap.min.css">
<!-- css custom -->
<link rel="stylesheet" href="style/main.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".sympa").fadeIn(4800).removeClass('hidden');
});
</script>
```
mstellaluna sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 386 | @ezioda004 |http://www.freecodecamp.org/ezioda004
git commit -m "Added 2 comments"
sympa
on it? If you can repost your code with the three backticks ``` on separate lines before and after the code it would make it easier to see, and also keep any code that might have been in there from being interpreted by the gitter page?
i use
nav{
position: fixed;
z-index: 2;
}
but i'm really bad at CSS so i'll suggest you ask for more opinions ^^
.airbag {
height: 60px;
}
/shame
gersho sends brownie points to @romchyfcc :sparkles: :thumbsup: :sparkles:
:cookie: 264 | @romchyfcc |http://www.freecodecamp.org/romchyfcc
/repeated[0]{2,}|repeated[1]{2,}/
this is a regex, try passing a string to RegExp()
var ist = repeated[0];
var znd = repeated[1];
var regex = new RegExp(ist + "{2,}|" + znd + "{2,}", 'gi');
coderprans sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8859 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
ostefani sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 526 | @kbaig |http://www.freecodecamp.org/kbaig
`
function permAlone(str) {
var repeated = str.split('').filter(function(item, i, ar){ return ar.indexOf(item) !== i; }).join('');
var ist = repeated[0];
var znd = repeated[1];
var regex = new RegExp(ist + "{2,}|" + znd + "{2,}", 'gi');
var perm = function(xs){
var ret=[];
for(var i=0;i<xs.length;i++){
var rest = perm(xs.slice(0,i).concat(xs.slice(i+1)));
if(!rest.length){
ret.push([xs[i]]);
}else{
for(var j=0;j<rest.length;j=j+1){
ret.push([xs[i]].concat(rest[j]));}
}
}
return ret;
};
var permute = [];
for(var i in perm(str)){
var z = perm(str)[i].join('');
permute.push(z);
}
var revised = [];
permute.forEach(function(x){
var y = x.replace(regex, '');
revised.push(y);
});
var result = revised.filter(function(x){ return x.length == str.length; });
return perm(str);
}
permAlone('abfdefa');
`
it works for almost all of them but for this str above it says potential infinite loop at line 28, where i push joined strings into permute. . why would it not work ..
submitMessage() {
this.setState({
input: ''
});
this.props.dispatch(submitNewMessage(this.state.input));
}
for my method - the error I'm getting is "submitNewMessage is not defined"
var permi = perm(str);
and use permi instead, but i dont understand why the previous one did not work.
submitMessage() { this.setState({input: ''}); this.props.submitNewMessage(this.state.input)); }
dispatch
of the action inside of submitNewMessage
: dispatch(addMessage(message))
submitNewMessage
function fully triggers the action already, without having to connect it to the store through dispatch anymore
html-joe sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1521 | @alpox |http://www.freecodecamp.org/alpox
engjell00 sends brownie points to @sjames1958gm and @marcusp619 :sparkles: :thumbsup: :sparkles:
:cookie: 394 | @marcusp619 |http://www.freecodecamp.org/marcusp619
:star2: 8860 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
1, 1, 2, 3, 5
. As you can see 1+1 = 2
, 1+2 = 3
, 2+3=5
and so on. So say you define x = 1
and y = 1
, you can guess the fibonacci sequence by doing z = x + y
. Now the next number would be sum of previous two numbers ie y + z
so all you need to do is assign them to each others.
feldbot sends brownie points to @ezioda004 and @mot01 and @marcusp619 :sparkles: :thumbsup: :sparkles:
:cookie: 388 | @ezioda004 |http://www.freecodecamp.org/ezioda004
:cookie: 395 | @marcusp619 |http://www.freecodecamp.org/marcusp619
:cookie: 960 | @mot01 |http://www.freecodecamp.org/mot01
function rot13(str) { // LBH QVQ VG!
str = str.split("");
var i;
for (i = 0; i < str.length; i++) {
str[i] = str[i].toString().charCodeAt(0) - 13;
str[i] = String.fromCharCode(str[i]);
}
return str.join("");
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
.charCodeAt(0) + 13
mauriciodeleonc sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 389 | @ezioda004 |http://www.freecodecamp.org/ezioda004