// jshint esversion:6
createPortal
guys can I get a review on my answer to find the longest word challenge?
function findLongestWord(str) {
var x = 0;
var num;
var array = str.split(' ');
array.forEach(function(item, x){
var y = item.length;
if(y > x){
x = y;
num = x;
}
});
console.log(num);
return num;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
function findLongestWord(str) {
var x = 0;
var num;
var array = str.split(' ');
array.forEach(function(item, x){
var y = item.length;
if(y > x){
x = y;
num = x;
}
});
console.log(num);
return num;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
germangamboa95 sends brownie points to @eweiss17 :sparkles: :thumbsup: :sparkles:
:cookie: 600 | @eweiss17 |http://www.freecodecamp.org/eweiss17
I'm working on the Caesar's Cipher challenge on FCC. I'm really stuck... again...
function rot13(str) { // LBH QVQ VG!
str = str.toUpperCase();
var output = [];
for (i = 0; i < str.length; i++){
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
output.push(str.charCodeAt(i));
} else {
output.push(str.charAt(i));
}
}
var outputString = "";
var changedCodeTemp = 0;
// this for loop will actually adjust the characters 13 spaces
for (j = 0; j < output.length; j++){
if (output[j] >= 65 && output[j] <= 90) {
if (output[j] >= 78){
changedCodeTemp = output[j] + 13;
changedCodeTemp = 65 + (changedCodeTemp - 90);
} else {
changedCodeTemp = output[j] + 13;
}
output[j] = String.fromCharCode(changedCodeTemp);
}
}
return output.join("");
}
I believe the fault could be in line 23 but when I think through it, it makes sense. It's supposed to go back to the beginning of the 65-90 range and continue if it exceeds a value of 90
changedCodeTemp = 65 + (changedCodeTemp - 90);
Uncaught ReferenceError: ReactBoostrap is not defined
at pen.js:16
@eweiss17 in
if(y > x){
x = y;
num = x;
}
What is the purpose of x = y;
?
jackhowa sends brownie points to @toianw :sparkles: :thumbsup: :sparkles:
:cookie: 506 | @toianw |http://www.freecodecamp.org/toianw
num
, maybe longest
. Instead of x
maybe i
which is often short for index
. y
could become currentLength
function findLongestWord(str) {
return Math.max(...str.split(' ').map(word => word.length));
}
jackhowa sends brownie points to @toianw :sparkles: :thumbsup: :sparkles:
germangamboa95 sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 493 | @kbaig |http://www.freecodecamp.org/kbaig
I'm working on the Caesar's Cipher challenge on FCC. I'm really stuck... again...
function rot13(str) { // LBH QVQ VG!
str = str.toUpperCase();
var output = [];
for (i = 0; i < str.length; i++){
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
output.push(str.charCodeAt(i));
} else {
output.push(str.charAt(i));
}
}
var outputString = "";
var changedCodeTemp = 0;
// this for loop will actually adjust the characters 13 spaces
for (j = 0; j < output.length; j++){
if (output[j] >= 65 && output[j] <= 90) {
if (output[j] >= 78){
changedCodeTemp = output[j] + 13;
changedCodeTemp = 65 + (changedCodeTemp - 90);
} else {
changedCodeTemp = output[j] + 13;
}
output[j] = String.fromCharCode(changedCodeTemp);
}
}
return output.join("");
}
I believe the fault could be in line 23 but when I think through it, it makes sense. It's supposed to go back to the beginning of the 65-90 range and continue if it exceeds a value of 90
function findLongestWord(str) {
return str.split(' ').reduce((a, b) => Math.max(a.length, b.length));
}
this is a better solution actually
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
output.push(str.charCodeAt(i));
} else {
output.push(str.charAt(i));
}
function init () {
const ini =
document.getElementByTagName("input").addEventListener("click", check);
}
function check(event){...use event.target.value for getting the clicked input value}
result += myArray[i]
and then after the loop $("#result").text(result);
juke-magic sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4641 | @masd925 |http://www.freecodecamp.org/masd925
@Xapuu
yes,I am creating my front and back end
'let targetNumber = Math.floor(Math.random() * 10) + 1;
function init () {
const ini =
document.getElementByTagName("input").addEventListener("click", check);
}
function check (event) {
if ( event.target.value == targetNumber) {
showWin();
} else if(event.target.value !== targetNumber){
showError();
}
else if ( (event.target.value !== targetNumber) && (ini >5) ) {
showLoss();
}'
javierpons sends brownie points to @marianissimus :sparkles: :thumbsup: :sparkles:
:cookie: 452 | @marianissimus |http://www.freecodecamp.org/marianissimus
let targetNumber = Math.floor(Math.random() * 10) + 1;
function init () {
const ini =
document.getElementByTagName("input").addEventListener("click", check);
}
function check (event) {
if ( (event.target.value !== targetNumber) && (ini >5) ) {
showLoss();
} else if(event.target.value !== targetNumber){
showError();
}
else if ( event.target.value == targetNumber)
{
showWin();
}
function showWin () {
const dele= document.getElementByTag('form');
elem.parentNode.removeChild('dele');
return 'You win!';
}
function showError () {
const dele= document.getElementByTag('form');
elem.parentNode.removeChild('dele');
return 'You make a mistake!';
}
function showLoss () {
const dele= document.getElementByTag('form');
elem.parentNode.removeChild('dele');
return 'Game Over!';
}
init();
sursider sends brownie points to @javierpons :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @javierpons |http://www.freecodecamp.org/javierpons
<input type="text" name="number" id"input">
---> <input type="text" name="number" id="input">
(you missed the =
in the attribute. The input could not be found in the javascript because of this. 2.: When you put a button in a form, the submission will reload the page and thus stop your javascript execution (And remove all results from before) You can prevent this by either removing the form from the html or adding event.preventDefault()
into the check
function
ini
inside of the function check
but ini
is not defined in that context - because it was defined locally only in the function init
ini
is undefined even there, because you assign the return value of addEventListener
to it - which is undefined (It has no return value)
const input = document.getElementById("input");
input.value
document.getElementByTag
does not exist btw. Its document.getElementByTagName
elem.parentNode.removeChild("dele");
input.value.addEventListener
is just wrong, you want event listener on submit
var images = [];
var sources = ["pic1.jpg","pic2.jpg"];
sources.forEach(function(source){
var img = new Image();
img.src = source;
images.push(img);
});
ingundela sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4642 | @masd925 |http://www.freecodecamp.org/masd925
primuscovenant sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 2131 | @heroiczero |http://www.freecodecamp.org/heroiczero
Hi guys, I'm going through the ES6 beta curriculum and can't continue because I can't solve "Destructing Assignment".
Here is the example:
function getLength(str) {
"use strict";
// change code below this line
const length = 0; // change this
// change code above this line
return len; // you must assign length to len in line
}
I don't even know where to begin
This is what I should do:
Use destructuring to obtain the length of the input string str, and assign the length to len in line.
ingundela sends brownie points to @sehban :sparkles: :thumbsup: :sparkles:
:cookie: 55 | @sehban |http://www.freecodecamp.org/sehban
event.preventDefault()
except it has to be in the outermost block of the function - not in an if or so. I'd put it in the beginning of the function or the end
length
the length
property of str
const obj = { fname: 'Kaz', lname: 'Baig' };
const { fname, lname } = obj;
console.log(fname + ' ' + lname); // 'Kaz Baig'
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var count=0;
$('#commentForm').submit(function(event) {
count++;
$('#countContainer').append('Total comments:'+ count);
$('#commentsContainer').append('<div style="background-color:green">'+$(newCommentText).val()+'</div>');
});
});
</script>
<style type="text/css">
#newCommentContainer {
/border-color: black;
border-style: solid;
border-width: 1px;
margin: 4% 24% 1% 24%;
padding: 1% 1% 1% 1%;
}
#commentsContainer {
border-color: black;
border-style: solid;
border-width: 1px;
margin: 0% 24% 1% 24%;
padding: 0% 1% 1% 1%;
}
#countContainer {
text-align: left;
}
#newCommentAuthor {
margin-bottom: 5px;
}
</style>
<title></title>
</head>
<body>
<div class="commentWidgetContainer">
<div id="newCommentContainer">
<form id="commentForm">
<input id="newCommentAuthor" type="text" name="name" placeholder="Name" autofocus><br>
<textarea id="newCommentText" rows="4" cols="50" name="comment-box" placeholder="Enter your comment here"></textarea><br>
<input type="submit" value="Submit">
</form>
</div>
<div id="commentsContainer">
<div id="countContainer"></div>
</div>
</div>
</body>
</html>
Hello can someone please tell why the html generated by append function does not stay. I mean it run properly but the generated html blinks when the code is run
$("#formid").submit(function (e) {
e.preventDefault();
:cookie: 949 | @mot01 |http://www.freecodecamp.org/mot01
zlfnhmd sends brownie points to @mot01 and @mbosnjak01 :sparkles: :thumbsup: :sparkles:
:cookie: 216 | @mbosnjak01 |http://www.freecodecamp.org/mbosnjak01
./*
- to like watch all the files maybe
files
flag is to specify a directory, not files
--files="*.html"
aftabparvez sends brownie points to @kbaig and @mot01 :sparkles: :thumbsup: :sparkles:
:cookie: 495 | @kbaig |http://www.freecodecamp.org/kbaig
:cookie: 950 | @mot01 |http://www.freecodecamp.org/mot01
if (navigator.geolocation){.......
import { ModuleWithProviders, NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { Router, Event, NavigationStart, NavigationEnd } from '@angular/router';
import { Base } from './components/base/base';
import { LoadingsWithOverlaps } from './components/Loading/Loadings-with-overlaps';
import { AiringFOXInfoPopup } from './components/Loading/airing-FOXinfo-popup';
import { Listings } from './components/listings/listings';
import { ScoringsMain } from './components/Scorings/ScoringsMain';
import { ScoringFOXTBA } from './components/Scorings/ScoringFOXTBA';
e';
const appRoutes: Routes = [
{
path: '',
redirectTo: 'jumping',
pathMatch: 'full'
},
{
path: 'FlyingManagement',
component: FlyingsHeader,
children: [
{ path: '', redirectTo: 'FlyingSearch', pathMatch: 'full' },
{ path: 'FlyingSearch', component: FlyingSearch },
{
path: 'FlyingMain/:id', component: FlyingMain,
children: [
{ path: '', redirectTo: 'Base', component: FlyingCreateFill, pathMatch: 'full' },
{ path: 'FlyingCreateFill', component: FlyingCreateFill, canDeactivate: [CanDeactivateGuard] },
]
}
]
},
{
path: 'Playing',
component: Development
},
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
//export class AppRoutingModule { }
declare var ADRUM: any;
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {
vpView: any;
// // Subscribe to the Router URL changes.
constructor(public appRoutes:Router) {
console.log("appDyanmics-sample-constructor");
this.appRoutes.events.subscribe((event:Event) => {
if (event instanceof NavigationEnd) {
console.debug('NavigationEnd: '+event.url);
this.vpView.markViewChangeEnd();
this.vpView.markViewDOMLoaded();
this.vpView.markXhrRequestsCompleted();
this.vpView.markViewResourcesLoaded();
this.vpView.end();
ADRUM.Scoring(this.vpView);
} else if (event instanceof NavigationStart) {
console.debug('NavigationStart: '+event.url);
this.vpView = new ADRUM.events.VPageView();
this.vpView.start();
this.vpView.markViewChangeStart();
}
});
}
}
if (navigator.geolocation){.......
from being true
navigator.geolocation
always evaluate to true?
navigator.geolocation
evaluates to false
eliecerthoms sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 499 | @kbaig |http://www.freecodecamp.org/kbaig
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var count=0;
$('#commentForm').submit(function(event) {
event.preventDefault();
count++;
$('#countContainer p').append(count);
$('#commentsContainer').append('<div id="comment'+count+'" style="background-color: #f1f1f1; padding: 5px 5px 5px 5px; margin-bottom: 5px; border-color: grey;border-style: solid;border-width: 1px; overflow: auto;"><div>'+$(newCommentAuthor).val()+' commented:</div><div>'+$(newCommentText).val()+'</div><hr><p class="replyArea"></p><textarea class="replyText" rows="4" cols="50" name="reply-box" placeholder="Enter your reply here"></textarea><br><button class="replyButton">Reply</button></div>');
$('.replyButton').click(function(event) {
$(this).siblings('.replyArea').prepend($(this).siblings('.replyText').val()+'<br>');
});
});
});
</script>
<style type="text/css">
#newCommentContainer {
border-color: black;
border-style: solid;
border-width: 1px;
margin: 4% 24% 1% 24%;
padding: 1% 1% 1% 1%;
}
#commentsContainer {
border-color: black;border-style: solid;border-width: 1px;
margin: 0% 24% 1% 24%;
padding: 0% 1% 1% 1%;
}
#countContainer {
text-align: left;
}
#newCommentAuthor {
margin-bottom: 5px;
}
</style>
<title></title>
</head>
<body>
<div class="commentWidgetContainer">
<div id="newCommentContainer">
<form id="commentForm">
<input id="newCommentAuthor" type="text" name="name" placeholder="Name" autofocus><br>
<textarea id="newCommentText" rows="4" cols="50" name="comment-box" placeholder="Enter your comment here"></textarea><br>
<input type="submit" value="Submit">
</form>
</div>
<div id="commentsContainer">
<div id="countContainer"><p>Total comments: </p></div>
</div>
</div>
</body>
</html>
Guys so there is bug which causes extra replies in the previous comment when new comments are added. the replies get multiplied from top to bottom.
So when i make the first comment and make replies to it, it works perfectly.
When I make the second comment, the replies in second comment work perfectly but when i reply to the first comment the reply is added twice and son on
Please help me out
neovks sends brownie points to @eweiss17 :sparkles: :thumbsup: :sparkles:
:cookie: 601 | @eweiss17 |http://www.freecodecamp.org/eweiss17
https://codepen.io/zlfnhmd/pen/BJYPwZ
Guys so there is bug which causes extra replies in the previous comment when new comments are added. the replies get multiplied from top to bottom.
So when i make the first comment and make replies to it, it works perfectly.
When I make the second comment, the replies in second comment work perfectly but when i reply to the first comment the reply is added twice and son on
Please help me out
@zlfnhmd I think each time you add a reply, you're adding the listener to each reply button
Do you mean each time I add a comment?
$(".replyButton").unbind('click');
zlfnhmd sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 501 | @kbaig |http://www.freecodecamp.org/kbaig
transition
for that)? Also I'd make the quote container smaller in width
jacobstewart1 sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 503 | @kbaig |http://www.freecodecamp.org/kbaig
jacobstewart1 sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles: