davidbelmares sends brownie points to @jtan3 :sparkles: :thumbsup: :sparkles:
:cookie: 466 | @jtan3 |http://www.freecodecamp.org/jtan3
this
function palindrome(str) {
var strWithoutSpecial = str;
var strWSandLower = strWithoutSpecial.toLowerCase();
var toReplace = /[^A-Za-z0-9_]/g;
strWSandLower = strWSandLower.replace(toReplace, "");
strWSandLower = strWSandLower.split("");
var reverseStr = strWSandLower.reverse("");
reverseStr = reverseStr.join("");
console.log(reverseStr);
return reverseStr == strWSandLower;
}
palindrome("eye");
function palindrome(str) {
var strWithoutSpecial = str;
var strWSandLower = strWithoutSpecial.toLowerCase();
var toReplace = /[^A-Za-z0-9_]/g;
strWSandLower = strWSandLower.replace(toReplace, "");
strWSandLower = strWSandLower.split("");
var reverseStr = strWSandLower.reverse("");
reverseStr = reverseStr.join("");
console.log(reverseStr);
console.log(strWSandLower);
// return reverseStr == strWSandLower;
}
undefined
palindrome("eye")
mot01 sends brownie points to @name and @davidbelmares :sparkles: :thumbsup: :sparkles:
:cookie: 234 | @davidbelmares |http://www.freecodecamp.org/davidbelmares
davidbelmares sends brownie points to @kkindorf :sparkles: :thumbsup: :sparkles:
:cookie: 342 | @kkindorf |http://www.freecodecamp.org/kkindorf
davidbelmares sends brownie points to @kkindorf :sparkles: :thumbsup: :sparkles:
```function palindrome(str) {
var originalString = str; originalString = originalString.toLowerCase();
var reversedStr = str.split(""); reversedStr = reversedStr.reverse(); reversedStr = reversedStr.join(""); reversedStr = reversedStr.toLowerCase();
originalString = originalString.replace(/[^a-z0-9]/g, "");
reversedStr = reversedStr.replace(/[^a-z0-9]/g, "");
return originalString == reversedStr;
}
palindrome("eyeE$@");
```function palindrome(str) {
var originalString = str; originalString = originalString.toLowerCase();
var reversedStr = str.split(""); reversedStr = reversedStr.reverse(); reversedStr = reversedStr.join(""); reversedStr = reversedStr.toLowerCase();
originalString = originalString.replace(/[^a-z0-9]/g, "");
reversedStr = reversedStr.replace(/[^a-z0-9]/g, "");
return originalString == reversedStr;
}
palindrome("eyeE$@");```
function palindrome(str) {
var originalString = str; originalString = originalString.toLowerCase();
var reversedStr = str.split(""); reversedStr = reversedStr.reverse(); reversedStr = reversedStr.join(""); reversedStr = reversedStr.toLowerCase();
originalString = originalString.replace(/[^a-z0-9]/g, "");
reversedStr = reversedStr.replace(/[^a-z0-9]/g, "");
return originalString == reversedStr;
}
palindrome("eyeE$@");
4 == 2 ? expressionTrue : expressionFalse ;
originalString = str; originalString = originalString.toLowerCase()
is redundant, just do originalString = str.toLowerCase()
, same goes for reversedStr, and besides that you don't need the originalString
variable, just rename the variable that the function takes to originalString
.
reversedStr = str.split("")
, because if you look above it you made originalStr
lowercase whereas reversedStr
will not be lowercase
img-fluid
<figcaption>
element or just use simple text tag either p, h1, h2
this.move
into setInterval. It is not a method anymore, just a function. Therefore this
points to the window
, when it is executed.
setInterval(this.move.bind(this),20);
could work.
primuscovenant sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 2118 | @heroiczero |http://www.freecodecamp.org/heroiczero
<button class="search-btn tab-btn" data-content="search-view" on-click="toggle">btn1</button>
<button class="customize-btn tab-btn" data-content="customize-view" on-click="toggle">btn2</button>
<div class="auto-complete-view" id="search-view"></div>
<div class="customize-view" id="customize-view"></div>
<script>
var tabBtn = this.shadowRoot.querySelectorAll('.tab-btn');
var customizeView = this.shadowRoot.getElementById('customize-view');
var searchView = this.shadowRoot.getElementById('search-view');
var closeBtn = this.shadowRoot.getElementById('closeBtn');
tabBtn.forEach(btn => {
btn.addEventListener('click', function(e){
if(e.target.dataset.content === 'search-view') {
this.classList.toggle('active');
searchView.style.display = "block";
customizeView.style.display = "none";
} else if (e.target.dataset.content === 'customize-view') {
this.classList.toggle('active');
customizeView.style.display = "block";
searchView.style.display = "none";
} else {
this.classList.removeClass('active');
}
});
closeBtn.addEventListener('click', function(e) {
tabBtn.classList.remove('active');
})
})
</script>
deepak2322 sends brownie points to @mot01 and @theoutlander :sparkles: :thumbsup: :sparkles:
:cookie: 943 | @mot01 |http://www.freecodecamp.org/mot01
@kodinglife "Chrome my block continued non-https request to your browser so your code may work one day and not a week later.
By adding https://cors-anywhere.herokuapp.com, it solve the issue.
Everyone should try it.
"
.map(x => x.filter(r => {
let dbTime = new Date(r.createdAt);
let lastThirty = Date.now() - 30*24*60*60*1000;
console.log(`Created At ${r.createdAt}, dbtime: ${dbTime.getTime()}`);
console.log(`Last Thirty ${lastThirty}`);
console.log(`Now: ${Date.now()}`);
console.log(dbTime.getTime() > lastThirty);
return dbTime.getTime() >= lastThirty;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>maxi</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<input id="search1" placeholder="enter playername">
<input id="search2" placeholder="enter playerscore">
<button class="btn-primary">click</button>
<div class="well"></div>
</body>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type : "POST",
url : "http://localhost:4000/api/ninjas",
data :{
"name" : $("#search1").val(),
"rank" : $("#search2").val()
},
success : function(data){
console.log(data);
},
error : function(err){
console.log('error' ,err);
}
});
});
});
</script>
</html>
input
tag , the server is not accepting those data's y?
postman
its working properly !
eval(f + operator + s);
smefinka sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8804 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
function findLongestWord(str) {
var strLetters = str.split(""); // stores each individual character of the input
var strWords = []; // stores each word of input string in separate indexes
var strCurrentWord = []; // temporary storage for the letters of each word before it's joined to make currentWord
var currentWord = ""; // temporary storage for each word before it's added to strWords
for (i=0; i < strLetters.length; i++){ // loops through letters of input string
if (strLetters[i] != " ") { // if the current character of the input string...
strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
} else { // ...is a whitespace then we know we're at the end of the current word.
strCurrentWord.pop(); // pop the whitespace (last value) out of the array
currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
console.log(strCurrentWord); // for debugging
currentWord = ""; // clear temporary variable
strCurrentWord = []; // same as above line
}
i++; //this extra increment skips over the whitespace to prevent infinite looping
}
var lengthOfLongestWord; // self explanatory
for (i = 0; i < strWords.length; i++) { // loops through array containing extracted words from input string
if (strWords[i].length > lengthOfLongestWord){ // if the length of the current word is greater than the previous longest word
lengthOfLongestWord = strWords[i].length; // update that record to reflect it
}
}
return lengthOfLongestWord; // return length of longest word
}
findLongestWord("The quick brown fox jumped over the lazy dog");
I'm having trouble with this code not working... I've looked over the logic, even explained it to myself with all those comments but I still can't see what's wrong. Thanks to anyone who helps
function findLongestWord(str) {
var strLetters = str.split(""); // stores each individual character of the input
var strWords = []; // stores each word of input string in separate indexes
var strCurrentWord = []; // temporary storage for the letters of each word before it's joined to make currentWord
var currentWord = ""; // temporary storage for each word before it's added to strWords
// loops through letters of input string
for (i=0; i < strLetters.length; i++){
// if the current character of the input string...
if (strLetters[i] != " ") {
strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
// ...is a whitespace then we know we're at the end of the current word.
} else {
strCurrentWord.pop(); // pop the whitespace (last value) out of the array
currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
console.log(strCurrentWord); // for debugging
currentWord = ""; // clear temporary variable
strCurrentWord = []; // same as above line
}
i++; //this extra increment skips over the whitespace to prevent infinite looping
}
var lengthOfLongestWord; // self explanatory
// loops through array containing extracted words from input string
for (i = 0; i < strWords.length; i++) {
// if the length of the current word is greater than the previous longest word
if (strWords[i].length > lengthOfLongestWord){
lengthOfLongestWord = strWords[i].length; // update that record to reflect it
}
}
return lengthOfLongestWord; // return length of longest word
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Nope
while (comScore < 5 && playScore < 5){
const keys = document.querySelector('#keys');
keys.addEventListener('click', function(e) {
const rock = e.target.className
if(e.target.className == 'rock' && pick == "scissors" || e.target.className == 'scissors' && pick == "paper" || e.target.className == 'paper' &&pick == "rock") {
document.getElementById("choice").innerHTML = "Alright you won!";
playScore++
document.getElementById("scorePlayer").innerHTML = playScore;
} else if(e.target.className == 'rock' && pick == "paper" || e.target.className == 'paper' && pick == "scissors" || e.target.className == 'scissors' &&pick == "rock") {
document.getElementById("choice").innerHTML = "You have lost! Computer choice was: " + pick;
comScore++
document.getElementById("scoreCom").innerHTML = comScore;
} else if(e.target.className == pick) {
document.getElementById("choice").innerHTML = "You are tie!";
}
})
}
.length
of each word to get the length. Then just find the longest one? Your approach could work but you are working too hard, I think...
.push
that letter into the array for your word - if you're just ending up being off by a digit in the length, that could be it? And if you're ending up being off by more, your i++
at the end is causing it to skip every other letter.
var lengthOfLongestWord;
will also help tremendously. You are trying to compare something to it, and if it is undefined, you will not get a good comparison.
davidbelmares sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3628 | @khaduch |http://www.freecodecamp.org/khaduch
cjrutherford sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 471 | @gothamknight |http://www.freecodecamp.org/gothamknight
gothamknight sends brownie points to @cjrutherford :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @cjrutherford |http://www.freecodecamp.org/cjrutherford
function findLongestWord(str) {
var strLetters = str.split(""); // stores each individual character of the input
var strWords = []; // stores each word of input string in separate indexes
var strCurrentWord = []; // temporary storage for the letters of each word before it's joined to make currentWord
var currentWord = ""; // temporary storage for each word before it's added to strWords
var i = 0;
// loops through letters of input string
for (i=0; i < strLetters.length; i++){
// if the current character of the input string...
if (strLetters[i] != " ") {
strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
// ...is a whitespace then we know we're at the end of the current word.
} else if (strLetters[i] == " ") {
currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
console.log(currentWord + "XDD"); // for debugging
currentWord = ""; // clear temporary variable
strCurrentWord = []; // same as above line
}
}
var lengthOfLongestWord = 1; // self explanatory
// loops through array containing extracted words from input string
for (i = 0; i < strWords.length; i++) {
// if the length of the current word is greater than the previous longest word
if (strWords[i].length > lengthOfLongestWord){
lengthOfLongestWord = strWords[i].length; // update that record to reflect it
}
}
return lengthOfLongestWord; // return length of longest word
}
findLongestWord("What if we try a super-long word such as otorhinolaryngology");
my current code for reference. I'm still looking for a solution myself
@DavidBelmares - well, there are a couple ways to fix it... one (a really sleazy way, so don't do this) would be to append a space onto the string so that you have an extra character to work with. Do not do that... The other way is to change the loop that is working with strLetters.length
to make it test for i <= strLetters.length
But then you have to be careful. because you don't want to access the array with the value of i
that is off the end of the array. So you would have to change the code inside the loop to be like this:
for (i=0; i <= strLetters.length; i++){
// if the current character of the input string...
if (i < strLetters.length && strLetters[i] != " ") {
strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
// ...is a whitespace then we know we're at the end of the current word.
} else {
currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
console.log(currentWord + "XDD"); // for debugging
currentWord = ""; // clear temporary variable
strCurrentWord = []; // same as above line
}
}
That allows your inner code to run one last time, but test the value of i
before you try to use it.
str.split(" ");
- it will directly dive you the array of words to do the individual checks. But your way should eventually work, just making a lot of extra steps that you are going through.
davidbelmares sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3629 | @khaduch |http://www.freecodecamp.org/khaduch
function findLongestWord(str) {
var strWords = str.split(" "); // stores each individual character of the input
var lengthOfLongestWord = 1; // self explanatory
// loops through array containing extracted words from input string
for (i = 0; i < strWords.length; i++) {
// if the length of the current word is greater than the previous longest word
if (strWords[i].length > lengthOfLongestWord){
lengthOfLongestWord = strWords[i].length; // update that record to reflect it
}
}
return lengthOfLongestWord; // return length of longest word
}
findLongestWord("What if we try a super-long word such as otorhinolaryngology");
Much cleaner code now
texas2010 sends brownie points to @davidbelmares :sparkles: :thumbsup: :sparkles:
:cookie: 236 | @davidbelmares |http://www.freecodecamp.org/davidbelmares