loss
loss
KPCKevin Powell - Community
Created by loss on 7/5/2024 in #front-end
eventListener on click
I'm dealing with a "simple issue". Basically, i want to put my code inside a function instead of passing directly in the button, but i'm having a issue where i don't know exactly how i'm supposed to do it, so. Here's the html, very simple:
<html !doctype>
<head></head>
<body>
<input id="text-input"></input>
<button id="check-btn">Click</button>
<p id="result"> test </p>

</body>
<script src="script.js"/>
<html !doctype>
<head></head>
<body>
<input id="text-input"></input>
<button id="check-btn">Click</button>
<p id="result"> test </p>

</body>
<script src="script.js"/>
the js:
const checkButton = document.getElementById("check-btn");
const input = document.getElementById("text-input");
const result = document.getElementById("result")


checkButton.addEventListener("click", ()=> {
if(input.value == ''){
alert ("Please input a value");
} //it works like this
})

//but once i put like this, i just can't make it work
const checkIsEmpty = () => {
if(input.value == ''){
alert ("Please input a value");
}
}

checkButton.addEventListener("click", checkIsEmpty())
const checkButton = document.getElementById("check-btn");
const input = document.getElementById("text-input");
const result = document.getElementById("result")


checkButton.addEventListener("click", ()=> {
if(input.value == ''){
alert ("Please input a value");
} //it works like this
})

//but once i put like this, i just can't make it work
const checkIsEmpty = () => {
if(input.value == ''){
alert ("Please input a value");
}
}

checkButton.addEventListener("click", checkIsEmpty())
68 replies
KPCKevin Powell - Community
Created by loss on 6/28/2024 in #front-end
How to access the last value?
So, basically this is my code:
function getAverage(scores) {
let value = 0;
for (let x in scores){
value += scores[x] / scores.length;
console.log(value);
};
}

console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]))
//right here should print 71.7
function getAverage(scores) {
let value = 0;
for (let x in scores){
value += scores[x] / scores.length;
console.log(value);
};
}

console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]))
//right here should print 71.7
And here is the output:
9.2
18
19.2
26.9
32.6
42.6
49.300000000000004
53.1
62.8
71.7
undefined
9.2
18
19.2
26.9
32.6
42.6
49.300000000000004
53.1
62.8
71.7
undefined
I have two issues. First, why is giving underfined ? And everytime i change the console.log(value) to return value is not returning the others values, always end on the 9.2, so i'm kinda lost on it. Sorry if i explained bad, english is not my first language
28 replies
KPCKevin Powell - Community
Created by loss on 8/17/2023 in #back-end
I can't make this work once i deploy
I'm trying to deploy this code on Vercel but is always not working, the only thing it said it was to put {"author":"my name"} in one part of the .json, after this, i tried to deploy and i can't manage to find a way to make this app run ): i'm trying this course from codecamp: https://www.freecodecamp.org/learn/back-end-development-and-apis/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package The application deployed: https://boilerplate-npm-9x5q.vercel.app/ The code with only the change at the .json file: https://github.com/kelvscode/boilerplate-npm
2 replies
KPCKevin Powell - Community
Created by loss on 7/7/2023 in #front-end
Constructor functions and usage
So, i'm going over again this topic and just to clarify, i understand that when i do:
function User(name) {
this.name = name;

this.sayName = function() {
console.log(`Meu nome é ${this.name}`)
}
}
;
function User(name) {
this.name = name;

this.sayName = function() {
console.log(`Meu nome é ${this.name}`)
}
}
;
I'm like creating a function that will create a new object with all properties of the constructor, right? Something like that (sorry my bad english). And when i do:
let adam = new Usuario("adam");
let adam = new Usuario("adam");
Will already have the methods and properties referenced before but can someone give me a more complex and a real life example to when i will or how i can use that in a project itself? (personal or not) so i can understand fully the potential on how to work with Constructors.
27 replies
KPCKevin Powell - Community
Created by loss on 7/2/2023 in #front-end
React Ecosystem
Sorry, i asked in the wrong channel before. Can someone give me insights about this and the recommendations? I just found this video and was wondering about how good it actually is to have as a guide. https://www.youtube.com/watch?v=6j9tnGMbm2c
6 replies
KPCKevin Powell - Community
Created by loss on 6/28/2023 in #os-and-tools
files in cloud
Does anyone here use any cloud solution to put all your files? I was wondering about putting all the files from my hd to cloud and have more free space at my pc itself, so if anyone does this and can give me better insights on how optimal this can be, i would appreciate (:
4 replies
KPCKevin Powell - Community
Created by loss on 6/13/2023 in #front-end
token is undefined
23 replies
KPCKevin Powell - Community
Created by loss on 6/10/2023 in #ui-ux
General opinions?
81 replies