Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 4928

Need sum help

by Komandow - 30 June, 2022 - 08:38 PM
This post is by a banned member (Komandow) - Unhide
Komandow  
Heaven
2.046
Posts
531
Threads
2 Years of service
#1
hey so idk anything about js so pls bare with me
so im working on a website and there is like a let list

let example=[

'whatever1',
'whatever2',
'whatever3',

];

now what if i want to include a ' or a , in my whatever1 for example
it fucks it up
any way around it
sorry if i sound like an idiot idk anything about js Pepe
This post is by a banned member (Summer) - Unhide
Summer  
Godlike
2.051
Posts
355
Threads
4 Years of service
#2
(This post was last modified: 01 July, 2022 - 07:55 PM by Summer. Edited 1 time in total. Edit Reason: added photo )
(30 June, 2022 - 08:38 PM)Komandow Wrote: Show More
hey so idk anything about js so pls bare with me
so im working on a website and there is like a let list

let example=[

'whatever1',
'whatever2',
'whatever3',

];

now what if i want to include a ' or a , in my whatever1 for example
it fucks it up
any way around it
sorry if i sound like an idiot idk anything about js Pepe

Np bro, So from what I understood of what you asked you could do something like this if you can get a random whatever
 
Code:
 
let example=[
    'whatever1',
    'whatever2',
    'whatever3'
   
];
const randomwhatever = () => example[Math.floor(Math.random() * example.length)]
function main(){
    const whatevers = randomwhatever();
    console.log(whatevers)
}
main();

Output: 
[Image: Cmpd3fJ.png]
Now can you explain the a part again I don't really understand what your saying add a?
Thanks hopefully this helps
[Image: 4v63n7I.gif]
This post is by a banned member (Komandow) - Unhide
Komandow  
Heaven
2.046
Posts
531
Threads
2 Years of service
#3
(01 July, 2022 - 07:52 PM)Summer Wrote: Show More
(30 June, 2022 - 08:38 PM)Komandow Wrote: Show More
hey so idk anything about js so pls bare with me
so im working on a website and there is like a let list

let example=[

'whatever1',
'whatever2',
'whatever3',

];

now what if i want to include a ' or a , in my whatever1 for example
it fucks it up
any way around it
sorry if i sound like an idiot idk anything about js Pepe

Np bro, So from what I understood of what you asked you could do something like this if you can get a random whatever
 
Code:
 
let example=[
    'whatever1',
    'whatever2',
    'whatever3'
   
];
const randomwhatever = () => example[Math.floor(Math.random() * example.length)]
function main(){
    const whatevers = randomwhatever();
    console.log(whatevers)
}
main();

Output: 
[Image: Cmpd3fJ.png]
Now can you explain the a part again I don't really understand what your saying add a?
Thanks hopefully this helps

for exmaple if i try to replace
'whatever1,' with 'what,ever1,'
you see how that makes it stop working
This post is by a banned member (Summer) - Unhide
Summer  
Godlike
2.051
Posts
355
Threads
4 Years of service
#4
(This post was last modified: 01 July, 2022 - 09:18 PM by Summer.)
(01 July, 2022 - 08:39 PM)Komandow Wrote: Show More
(01 July, 2022 - 07:52 PM)Summer Wrote: Show More
(30 June, 2022 - 08:38 PM)Komandow Wrote: Show More
hey so idk anything about js so pls bare with me
so im working on a website and there is like a let list

let example=[

'whatever1',
'whatever2',
'whatever3',

];

now what if i want to include a ' or a , in my whatever1 for example
it fucks it up
any way around it
sorry if i sound like an idiot idk anything about js Pepe

Np bro, So from what I understood of what you asked you could do something like this if you can get a random whatever
 
Code:
 
let example=[
    'whatever1',
    'whatever2',
    'whatever3'
   
];
const randomwhatever = () => example[Math.floor(Math.random() * example.length)]
function main(){
    const whatevers = randomwhatever();
    console.log(whatevers)
}
main();

Output: 
[Image: Cmpd3fJ.png]
Now can you explain the a part again I don't really understand what your saying add a?
Thanks hopefully this helps

for exmaple if i try to replace
'whatever1,' with 'what,ever1,'
you see how that makes it stop working

Paste your whole function or file and i'll fix it for you

(01 July, 2022 - 08:39 PM)Komandow Wrote: Show More
(01 July, 2022 - 07:52 PM)Summer Wrote: Show More
(30 June, 2022 - 08:38 PM)Komandow Wrote: Show More
hey so idk anything about js so pls bare with me
so im working on a website and there is like a let list

let example=[

'whatever1',
'whatever2',
'whatever3',

];

now what if i want to include a ' or a , in my whatever1 for example
it fucks it up
any way around it
sorry if i sound like an idiot idk anything about js Pepe

Np bro, So from what I understood of what you asked you could do something like this if you can get a random whatever
 
Code:
 
let example=[
    'whatever1',
    'whatever2',
    'whatever3'
   
];
const randomwhatever = () => example[Math.floor(Math.random() * example.length)]
function main(){
    const whatevers = randomwhatever();
    console.log(whatevers)
}
main();

Output: 
[Image: Cmpd3fJ.png]
Now can you explain the a part again I don't really understand what your saying add a?
Thanks hopefully this helps

for exmaple if i try to replace
'whatever1,' with 'what,ever1,'
you see how that makes it stop working

Or you could replace all with a method like this 
 
Code:
 
const regex = require('regex')
let example=[
    'whatever1',
    'whatever2',
    'whatever3'
   
];
const randomwhatever = () => example[Math.floor(Math.random() * example.length)]
function main(){
    const whatevers = randomwhatever();
    const regex = /whatever/ig;
    console.log(whatevers.replaceAll(regex, 'what,ever'));
}
main();

Output: 
[Image: ipafxf8h.jpg]
That should be waht you mean no?
[Image: 4v63n7I.gif]

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)