/    Sign up×
Community /Pin to ProfileBookmark

Changing data value in a table

I’m making a very simple version of tic tac toe for my IT class I have everything working except I can’t get the cells in my table to show “X” or “O”. The background changes however the text doesn’t display. here’s a snipet of my script:

if (count%2 == 0)
{
var o = obj
if (o == countray[count])
{
alert(“Can’t Do That”)
}
else
{
o.style.fontSize=”70″
o.style.color=”black”;
o.data = “O”
o.style.background =”yellow”
alert(“Player 1”)
alert(o.id)
count++
countray[count] = o
}

}

else
{
var x = obj
if (x == countray[count])
{
alert(“Can’t Do That”)
}
else
{
x.style.fontSize=”70″
x.style.color=”black”;
x.data=”X”
x.style.background =”cyan” alert(“Player 2”)
alert(x.id)
count++
countray[count] = x
}

}

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@javaNoobieOct 19.2004 — <i>
</i>o.[color=red]firstChild[/color].data = "O";
x.[color=red]firstChild[/color].data = "X";
Copy linkTweet thisAlerts:
@mannyginda2gauthorOct 19.2004 — when I try that I get Error: 'firstChild' is null or not an object
Copy linkTweet thisAlerts:
@javaNoobieOct 19.2004 — How are you calling the function? Post/attach/link the codes.
Copy linkTweet thisAlerts:
@mannyginda2gauthorOct 19.2004 — I've attached it, thanks

[upl-file uuid=75cfc614-aa61-4236-8d24-336b7a09a70b size=2kB]tictactoe.txt[/upl-file]
Copy linkTweet thisAlerts:
@javaNoobieOct 19.2004 — Ok.. your table cell is empty, thus firstChild will not work. What you need to do is to append a textnode into it.
<i>
</i>o.appendChild(document.createTextNode("O"));
x.appendChild(document.createTextNode("X"));
Copy linkTweet thisAlerts:
@FangOct 19.2004 — You could have added &amp;nbsp; to the cells, then o.firstChild.data = "O"; would work.

Style the cells:
&lt;style type="text/css"&gt;
&lt;!--
#table td {
text-align:center;
font-size:4em;
}
--&gt;
&lt;/style&gt;


The logic is flawed; a player can play on one of his existing squares!
×

Success!

Help @mannyginda2g spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...