You are viewing our Forum Archives. To view or take place in current topics click here.
Javascript resource code please
Posted:
Javascript resource code please Posted:
Status: Offline
Joined: Sep 15, 201212Year Member
Posts: 323
Reputation Power: 12
Status: Offline
Joined: Sep 15, 201212Year Member
Posts: 323
Reputation Power: 12
I'm a pretty big noob in javascript and need help in a script for a chat room.
The script that I'm trying to make is a) Finds strings of text for e.g "Apple juice" if the text doesn't contain apple the script will activate.
Another example "Orange" The string did not contain the word apple the script now will execute.
I now this might be on the incorrect forum and I'm a noob in programming but I really need help in this.
Thanks for even reading, I would appreciate if you would respond if you knew even something about this subject !
~Pou
The script that I'm trying to make is a) Finds strings of text for e.g "Apple juice" if the text doesn't contain apple the script will activate.
Another example "Orange" The string did not contain the word apple the script now will execute.
I now this might be on the incorrect forum and I'm a noob in programming but I really need help in this.
Thanks for even reading, I would appreciate if you would respond if you knew even something about this subject !
~Pou
#2. Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
You can use the .includes() method which will return true or false depending on whether the original string contains the substring.
Example:
You can use the return value from the .includes() method to act upon the original string.
One thing to note is that I'm fairly certain that the .includes() method is NOT case-sensitive.
Example:
var myString = Welcome to The Tech Game;
var a = myString.includes("The"); // a will be true
var b = myString.includes("Hello"); // b will be false
You can use the return value from the .includes() method to act upon the original string.
var myString = "OrangesApplesBananas";
if (myString.includes("apple")) {
// The string contains "apple".
// Do stuff here
} else {
// The string does not contain "apple".
// Do other stuff here
}
One thing to note is that I'm fairly certain that the .includes() method is NOT case-sensitive.
- 1useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Sep 15, 201212Year Member
Posts: 323
Reputation Power: 12
Status: Offline
Joined: Sep 15, 201212Year Member
Posts: 323
Reputation Power: 12
-Deano wrote You can use the .includes() method which will return true or false depending on whether the original string contains the substring.
Example:
var myString = Welcome to The Tech Game;
var a = myString.includes("The"); // a will be true
var b = myString.includes("Hello"); // b will be false
You can use the return value from the .includes() method to act upon the original string.
var myString = "OrangesApplesBananas";
if (myString.includes("apple")) {
// The string contains "apple".
// Do stuff here
} else {
// The string does not contain "apple".
// Do other stuff here
}
One thing to note is that I'm fairly certain that the .includes() method is NOT case-sensitive.
Ah thanks for replying! I appreciate your help a lot !! <3
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
-Deano wrote You can use the .includes() method which will return true or false depending on whether the original string contains the substring.
Example:
var myString = Welcome to The Tech Game;
var a = myString.includes("The"); // a will be true
var b = myString.includes("Hello"); // b will be false
You can use the return value from the .includes() method to act upon the original string.
var myString = "OrangesApplesBananas";
if (myString.includes("apple")) {
// The string contains "apple".
// Do stuff here
} else {
// The string does not contain "apple".
// Do other stuff here
}
One thing to note is that I'm fairly certain that the .includes() method is NOT case-sensitive.
Since OP said they were new to javascript. I will add to this.
If you want to check if it doesn't include something, most beginners would set their code up like this.
if (myString.includes('apple') === false) {
alert("foo");
}
Which is fine, but it isn't the simplified version.
So here is a simpler way of writing it. (not the most simple though)
if(!myString.includes('apple'){
alert("foo");
}
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.