Garmaine Staff asked 2 years ago

I need to print in the table the values x and y and where the button goes.
But how to solve it? I tried creating a function called createTable() but it doesn't work.

JavaScript code:

function moveBtn() {
var $button = $("#btn");
    var maxLeft = $("#sq").innerWidth()- $button.width();
    var maxTop = $("#sq").innerHeight() - $button.height();
    var leftPos = Math.floor(Math.random() * (maxLeft));
    var topPos = Math.floor(Math.random() * (maxTop));
    $button.css({ left: leftPos, top: topPos }).fadeIn(1000);
    console.log('x: ' + leftPos + ' y: ' + topPos);
    return leftPos, topPos;


function createtable(posx,posy) {
document.getElementById("#ax").value = posx[i];


var posx = new Array();
var posy= new Array();

And his my HTML to generate the table:

<table align="left" style="padding-left: 900px;" id="tables">
        <tr style="vertical-align: text-top;">
        <th style="padding: 15px;">&nbsp&nbsp&nbsp X &nbsp&nbsp&nbsp</th>
        <th style="padding: 15px;">&nbsp&nbsp&nbsp Y &nbsp&nbsp&nbsp</th>
            <td id="ix"><p id="ax"></p></td>
            <td id="iy"><p></p id="ay"></td>
<div class="square" id="sq">
    <button id="btn" class="btn btn-primary btn-sm" onclick="pressButton();">HazClick!</button>