37 Replies
hello
'''js
let text = '';
let neshon = '';
ar = [1,2,3,4,5,6]
win=[1]
loss=[1]
function submiter1(){
let getter = document.getElementById('n1').value = 1; let random = ar[(Math.floor(Math.random() * ar.length))];
if(getter == random ){ for(let i =0; i<=win; i++){ neshon += win; }
text = random; document.getElementById('brande').innerHTML = 'brande shodid '; document.getElementById('shower').innerHTML = 'adad bod'+' ' + text; document.getElementById('win').innerHTML = neshon;
}else{ loss + 1 document.getElementById('brande').innerHTML = 'shoma bakhtid '; document.getElementById('shower').innerHTML = 'adad bod'+' ' + random; document.getElementById('loss').innerHTML = loss; } } "'' why in for it not give +1 to win ? and it just show the 1 close it it ? like 1+1 = 2 but it show 11 i was know problem but i forget
let getter = document.getElementById('n1').value = 1; let random = ar[(Math.floor(Math.random() * ar.length))];
if(getter == random ){ for(let i =0; i<=win; i++){ neshon += win; }
text = random; document.getElementById('brande').innerHTML = 'brande shodid '; document.getElementById('shower').innerHTML = 'adad bod'+' ' + text; document.getElementById('win').innerHTML = neshon;
}else{ loss + 1 document.getElementById('brande').innerHTML = 'shoma bakhtid '; document.getElementById('shower').innerHTML = 'adad bod'+' ' + random; document.getElementById('loss').innerHTML = loss; } } "'' why in for it not give +1 to win ? and it just show the 1 close it it ? like 1+1 = 2 but it show 11 i was know problem but i forget
+ concatenates strings (sticks them together), and when one half of the arguments around + is a string, and the other is a number, it converts the number into a string and puts them together
witch one is string?
neshon is a string
let neshon = '';
hmm
(also, the code blocks use backticks, not quotes. It's left of the 1 key on a qwerty keyboard)
and if you type, say ```js, it will do syntaxt highlighting which makes code a lot easier to read
i do but not work
oh wrong key
"''
so i should re place neshon?
if it's only used to store a number, you can initialize it as 0 instead of ''
let neshon = 0;
u mean like this?
yeah, that would probably be enough
no i try but not work
still not +
only show each other near each other
Win : 01111111
try
neshon = parseInt(neshon) + parseInt(win);
hmm
i think when im using this it not show 1 anymore
let getter = document.getElementById('n1').value = 1;
so it never give me win
maybe make a codepen then, so that people can run the code themselves. I've got a meeting to go to now
Aright i will try thath
This is returning a string, which is causing the issue. You want to use
valueAsNumber
,
let getter = document.getElementById('n1').valueAsNumber = 1;
but why it still not + and show 1 near each other
Win : 1111
Are you trying to set or get the value? You named the variable
getter
but you’re using =
with is setting the valueim making a game if the getter be az same == az random number it show u win and 1+ to the win leaderboard
and all code fine but it not +1 to win and show it near each other like this Win : 1111 but i want to show like win 1 win 2 win 3
do u know the problem?
dont look at the names cuse first i was getting number from input but i chenge it to stactic value so i make 6 button with 6 number 1.2.3.4.5.6
Instead of saying “post no attention to the name” you should name your variables better. Is confusing to anyone looking at your code (like those trying to help)
yes i know
i was gonna re name all stuff after i fix this bug
idk why this is happening
do u know what should i do for the bug?
Your
win
variable is an array. You’re trying to add an array and a number…which can’t be done. So JS is making everything a string. Change win
to a number and it should worki chenge it to what?
A number
it is 1
win=[1]
That’s an array, not a number
it work
let win=1;
there is no way i can use it in aray?
Of course there’s a way. But you’ll have to be more specific about your goal. What exactly sure you trying to accomplish?
i think for this part i dont need araye right ?
cuse all button put number in 1
so it only need 1
That depends on what you want to do. An array is used when you want to store and use multiple data points. Do you need more than one number? If so, why?
nop
i only need 1 to deposite score for win and another one to deposite score for loss
Then there’s no need for an array. You’re good to go 👍
tnx for help
it work fine now
just one thing
let win=1;
when i put win to 0
its not adding it 1 more
and when its 1 score start from 2 not 1
how should i fix this?
' ' and 0 not fix the problem
Share your correct code
Sorry, been at work all day >_<
Can you step me through your function here, let me know what you want it to do? Reading it as-is I can't make out what exactly you're trying to accomplish
hello sorry i dont cheak channel
im getting home in few hours and im gonna uplode it in code open