fanofcena wrote:
transparent wrote:
trinary wrote:
It can be occasionally useful.Well, I never use it because of inspect, but I always thought it was cool when I was first learning it.
I have used the contenteditable attribute though to create custom facebook like inputs :-) its cool.. allows u to do things that a normal textbox or input cant [ rich input ]
Inspect element you can color, bold, add images, etc.
Offline
mythbusteranimator wrote:
fanofcena wrote:
transparent wrote:
Well, I never use it because of inspect, but I always thought it was cool when I was first learning it.I have used the contenteditable attribute though to create custom facebook like inputs :-) its cool.. allows u to do things that a normal textbox or input cant [ rich input ]
Inspect element you can color, bold, add images, etc.
*facepalm*
Do you expect the user to be able to use inspector ? seriously ?
Offline
fanofcena wrote:
mythbusteranimator wrote:
fanofcena wrote:
I have used the contenteditable attribute though to create custom facebook like inputs :-) its cool.. allows u to do things that a normal textbox or input cant [ rich input ]Inspect element you can color, bold, add images, etc.
*facepalm*
Do you expect the user to be able to use inspector ? seriously ?
it makes sense using inspector
Offline
I need help.
I'm making a tic tac toe game, and I want to check if X or O won.
I have a variable called "grid", that is a multidimensional array.
In the middle of a game, it would look sorta like this (if I were declare it as if it were in the middle of a game)
grid[0]=[0,0,1]; //1's are X's, and 2's are O's grid[1]=[1,2,2]; grid[2]=[1,2,2];
To look at it as if it were on the screen, you would have to flip it 90 degrees, to make it so I can do grid[x][y], and not grid[y][x], but that's not the point.
In the function in which I check if someone one, I don't know how to check grid[0], or any in that matter. It doesn't work, I had it log this:
console.log(grid[0]); //this returned 0,0,0 console.log(grid[0]==0,0,0); //this returned false console.log(grid[0]==[0,0,0]); //this returned false
I also tried it with the 3 equal sign condition, but it still didn't return true (grid[0] was 0,0,0 according to the console log).
What did I do wrong?
EDIT: Just checked
console.log(grid[0]==000)//also with the 3 equal condition
and still didn't work...
Last edited by TorbyFork234 (2012-11-23 23:37:05)
Offline
In JS, you can't equality-test arrays (something I truly hate).
console.log(grid[0][0]==0 && grid[0][1]==0 && grid[0][2]==0);
Offline
Hardmath123 wrote:
In JS, you can't equality-test arrays (something I truly hate).
Code:
console.log(grid[0][0]==0 && grid[0][1]==0 && grid[0][2]==0);
Wait whaaaaaaaaaaa ?
Offline
It's a boolean statement to see if the following was true or not.
Offline
&& is boolean and.
So raining && cold means "raining and cold".
Or one && two && three means "one and two and three".
Or equals1 && equals2 && equals3... or grid[0][0]==0 && grid[0][1]==0 && grid[0][2]==0
Offline
scratchisthebest wrote:
&& is boolean and.
So raining && cold means "raining and cold".
Or one && two && three means "one and two and three".
Or equals1 && equals2 && equals3... or grid[0][0]==0 && grid[0][1]==0 && grid[0][2]==0
I know that, and that's what I did (since it's been about a week since I posted that).
I just wanted to know that why I can't do
grid[0]==[0,0,0]
?
I copy and pasted what it reported to an alert box (and also the console), and put that in the if statement. I kept on altering to see what kind it worked, but it didn't work. I was just wondering why it doesn't work. Doesn't the variable report what it contains, since it's apparently not doing that.
Offline
mythbusteranimator wrote:
Say
Are layers like Sprites?
(Just curious)
Well, kind of, if you're talking about Scratch layers -> javascript sprites, then not really.
Scratch layers are like the z-index of CSS, in which you can manipulate with javascript (if you know how).
If you're talking about Javascript sprites. Then, no.
If you want to set up a sprite (like how it is in Scratch), in javascript, you would have to make an object, and assign it all the attributes that scratch has, and also give it it's own images (or sprite strip images).
Offline
i have a question, how do you check if a string is valid hex code
function isValidHexCode(hexCode){
if(hexCode.length!==6){ //I know you can get three-character hex codes that are valid but I'll do that later
return FALSE;
}
var i;
var allowed=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
for(i=0; i<6; i++){ //Check all characters separately, so check the first character, then the second, etc.
if(!hexCode.charAt(i).toLowerCase() in allowed){
return FALSE;
}
}
return TRUE;
}
i tried that but it's not working
i tested it with
if(isValidHexCode("aaaaaa")){
alert("Yes");
}else{
alert("No");
}
if(isValidHexCode("zzzzzz")){
alert("Yes");
}else{
alert("No");
}
but it just wasn't alerting anything
i think it's the "in" part on line 8, i've never heard about the "in" operator before
i've probably made dozens of syntax errors i don't really know js too well
Offline
function isValidHexCode(hexCode){ if(hexCode.length!==6){ //I know you can get three-character hex codes that are valid but I'll do that later return 0; } var i; var allowed=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"); for(i=0; i<6; i++){ //Check all characters separately, so check the first character, then the second, etc. if(allowed.indexOf(hexCode.charAt(i).toLowerCase()) == -1){ return 0; } } return 1; }
Offline
RedRocker227 wrote:
i have a question, how do you check if a string is valid hex code
function isValidHexCode(hexCode){
if(hexCode.length!==6){ //I know you can get three-character hex codes that are valid but I'll do that later
return FALSE;
}
var i;
var allowed=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
for(i=0; i<6; i++){ //Check all characters separately, so check the first character, then the second, etc.
if(!hexCode.charAt(i).toLowerCase() in allowed){
return FALSE;
}
}
return TRUE;
}
i tried that but it's not working
i tested it with
if(isValidHexCode("aaaaaa")){
alert("Yes");
}else{
alert("No");
}
if(isValidHexCode("zzzzzz")){
alert("Yes");
}else{
alert("No");
}
but it just wasn't alerting anything
i think it's the "in" part on line 8, i've never heard about the "in" operator before
i've probably made dozens of syntax errors i don't really know js too well
from what I saw in w3schools (I'm no javascript expert, I still use it), there is no "in" operator. The only time that 'in' is used as something inside a parameter (besides for user defined functions), is the for (x in object).
What you should do instead is using IndexOf().
Although it is used for finding the item #, you can replicate the
<[list v] contains [thing v]>by having this
console.log(!arrayObject.indexOf('thing')==-1);
that should do what you want in the code above, if it's still wrong, then I don't know.
Edit: didn't scroll through bobbybee's code. It's shown in there too.
Sorry bobby.
Last edited by TorbyFork234 (2012-12-04 19:24:24)
Offline
The "in" is from coffeescript.
Offline
oh okay
thanks
Offline
mythbusteranimator wrote:
Do you need an "else" statement?
you don't need one, since the only way it will get to the part where it returns TRUE is if the hex code is valid
if it's not valid, it will never reach it to that point
also it's interesting that you have to return 0 or 1 instead of FALSE and TRUE
i guess i should research these things before i assume it's the same as in php
Offline
Java scripts great! I am making a chatbot. Also an RPGs, platformer, matrices calculator, and a few others. It's super cool. Also I use processing.js. I am making a mod where it converts scratch into JavaScript. Overall, great language! My mom hates bit when I commentate in JavaScript.
Offline
RedRocker227 wrote:
mythbusteranimator wrote:
Do you need an "else" statement?
you don't need one, since the only way it will get to the part where it returns TRUE is if the hex code is valid
if it's not valid, it will never reach it to that point
also it's interesting that you have to return 0 or 1 instead of FALSE and TRUE
i guess i should research these things before i assume it's the same as in php
I didn't actually know either, but it gave my syntax errors (and that kept it happy).
Offline
RedRocker227 wrote:
mythbusteranimator wrote:
Do you need an "else" statement?
you don't need one, since the only way it will get to the part where it returns TRUE is if the hex code is valid
if it's not valid, it will never reach it to that point
also it's interesting that you have to return 0 or 1 instead of FALSE and TRUE
i guess i should research these things before i assume it's the same as in php
you don't.
it works fine when you do
return true;
I never seemed to be able to do this, so can someone help me: I don't know how to turn a hex code into RGB,be able to edit the values, and then turn it back into hex.
Basically replicating the
change pen color by (number)
Last edited by TorbyFork234 (2012-12-05 18:50:43)
Offline
Hex code to RGB:
Seperate it into letters:
0xFF0000=
red = FF
green = 00
blue = 00;
Convert each value from hexadecimal to decimal (google it).
Modify values.
red = 255
green=255
blue=0
Convert each value from decimal to hexadecimal.
Concatenate together in order red, green, then blue.
0xFFFF00.
??
??
Profit!
Offline
You'd just have to convert the hex values of the RGB color to decimal - this gives you an integer between 0 (0x00) and 255 (0xFF) for each color.
edit: dhrnkljsgrnjklsgj ninja'd. I was going to explain how to convert from hex to decimal, but it wasn't clear :c Have a link instead.
Last edited by technoguyx (2012-12-05 19:21:27)
Offline