Forza
Forza

Reputation: 21

numbers in correct order display button

I'm working on a project where you have to put the above numbers 1/9 in the right order.

For example: 1-6-3

When the numbers are placed in the correct order, a button will appear to continue to the next page. Can someone help me with that?

function allowDrop(ev) {
  ev.preventDefault();
}

function drag(ev) {
  ev.dataTransfer.setData("Text", ev.target.id);
}

function drop(ev) {
  var data = ev.dataTransfer.getData("Text");
  ev.target.appendChild(document.getElementById(data));
  ev.preventDefault();
}
body {
  background-color: #cccccc;
}

.content-size {
  height: 300px;
  width: 300px;
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  background-color: #3e3e3e;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  border: 2px solid #3e3e3e;
}

.picure-1-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 20%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-2-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-3-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 20%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-4-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-5-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-6-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-7-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 80%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-8-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 80%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-9-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 80%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

#code-number-1 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-1:hover {
  color: #fdfdfda3;
}

#code-number-2 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-2:hover {
  color: #fdfdfda3;
}

#code-number-3 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-3:hover {
  color: #fdfdfda3;
}

#code-number-4 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-4:hover {
  color: #fdfdfda3;
}

#code-number-5 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
  border-radius: 35px;
}

#code-number-5:hover {
  color: #fdfdfda3;
}

#code-number-6 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-6:hover {
  color: #fdfdfda3;
}

#code-number-7 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
  border-radius: 35px;
}

#code-number-7:hover {
  color: #fdfdfda3;
}

#code-number-8 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
  border-radius: 35px;
}

#code-number-8:hover {
  color: #fdfdfda3;
}

#code-number-9 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-9:hover {
  color: #fdfdfda3;
}

.numbers-3 {
  height: 70px;
  width: 300px;
  position: fixed;
  left: 50%;
  top: 79%;
  transform: translate(-50%, -50%);
  background-color: #3a3939;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  border: 2px solid #3e3e3e;
}

a {
  color: #ffffff61;
  text-decoration: none;
  font-weight: bold;
  font-size: 13px;
  font-family: arial;
  cursor: pointer;
}

.reset {
  height: 50px;
  width: 150px;
  position: fixed;
  left: 50%;
  top: 95%;
  transform: translate(-50%, -50%);
  background-color: #444444f2;
  text-align: center;
  line-height: 50px;
  border-radius: 10px;
  border: 1px solid #d6d6d6;
}

.reset:hover {
  background-color: #353535f2;
}

#code-1 {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #525252bf;
  border-radius: 5px;
}

#code-2 {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #525252bf;
  border-radius: 5px;
}

#code-3 {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #525252bf;
  border-radius: 5px;
}
<div class="content-size">
  <div class="picure-1-box">
    <div draggable="true" id="code-number-1" ondragstart="drag(event)">
      1
    </div>
  </div>
  <div class="picure-2-box">
    <div draggable="true" id="code-number-2" ondragstart="drag(event)">
      2
    </div>
  </div>
  <div class="picure-3-box">
    <div draggable="true" id="code-number-3" ondragstart="drag(event)">
      3
    </div>
  </div>
  <div class="picure-4-box">
    <div draggable="true" id="code-number-4" ondragstart="drag(event)">
      4
    </div>
  </div>
  <div class="picure-5-box">
    <div draggable="true" id="code-number-5" ondragstart="drag(event)">
      5
    </div>
  </div>
  <div class="picure-6-box">
    <div draggable="true" id="code-number-6" ondragstart="drag(event)">
      6
    </div>
  </div>
  <div class="picure-7-box">
    <div draggable="true" id="code-number-7" ondragstart="drag(event)">
      7
    </div>
  </div>
  <div class="picure-8-box">
    <div draggable="true" id="code-number-8" ondragstart="drag(event)">
      8
    </div>
  </div>
  <div class="picure-9-box">
    <div draggable="true" id="code-number-9" ondragstart="drag(event)">
      9
    </div>
  </div>
</div>
<div class="numbers-3">
  <div id="code-1" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
  <div id="code-2" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
  <div id="code-3" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
</div>
<div class="reset">
  <a href=".">Reset</a>
</div>

Upvotes: 2

Views: 29

Answers (1)

Rojo
Rojo

Reputation: 2869

I used an array and parseInt to edit the array. It's kind of sketchy, but it works. I set the code to 1-6-3. It doesn't create a button to continue; it just validates the code.

function allowDrop(ev) {
  ev.preventDefault();
}

function drag(ev) {
  ev.dataTransfer.setData("Text", ev.target.id);
}

var input_code = [-1, -1, -1];

function drop(ev) {
  var data = ev.dataTransfer.getData("Text");
  ev.target.appendChild(document.getElementById(data));
  input_code[parseInt(ev.target.id.split('-')[1], 10)-1] = parseInt(document.getElementById(data).innerText, 10);
  if (input_code.toString() === [1, 6, 3].toString()) {
    console.log("correct");
    // append your button
  }
  ev.preventDefault();
}
body {
  background-color: #cccccc;
}

.content-size {
  height: 300px;
  width: 300px;
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  background-color: #3e3e3e;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  border: 2px solid #3e3e3e;
}

.picure-1-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 20%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-2-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-3-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 20%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-4-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-5-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-6-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-7-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 80%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-8-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 80%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

.picure-9-box {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 80%;
  transform: translate(-50%, -50%);
  background-color: #3a3a3a;
  border-radius: 35px;
}

#code-number-1 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-1:hover {
  color: #fdfdfda3;
}

#code-number-2 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-2:hover {
  color: #fdfdfda3;
}

#code-number-3 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-3:hover {
  color: #fdfdfda3;
}

#code-number-4 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-4:hover {
  color: #fdfdfda3;
}

#code-number-5 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
  border-radius: 35px;
}

#code-number-5:hover {
  color: #fdfdfda3;
}

#code-number-6 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-6:hover {
  color: #fdfdfda3;
}

#code-number-7 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
  border-radius: 35px;
}

#code-number-7:hover {
  color: #fdfdfda3;
}

#code-number-8 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
  border-radius: 35px;
}

#code-number-8:hover {
  color: #fdfdfda3;
}

#code-number-9 {
  font-size: 15px;
  font-family: arial;
  text-align: center;
  line-height: 50px;
  color: #868686;
  font-weight: bold;
  cursor: grab;
}

#code-number-9:hover {
  color: #fdfdfda3;
}

.numbers-3 {
  height: 70px;
  width: 300px;
  position: fixed;
  left: 50%;
  top: 79%;
  transform: translate(-50%, -50%);
  background-color: #3a3939;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  border: 2px solid #3e3e3e;
}

a {
  color: #ffffff61;
  text-decoration: none;
  font-weight: bold;
  font-size: 13px;
  font-family: arial;
  cursor: pointer;
}

.reset {
  height: 50px;
  width: 150px;
  position: fixed;
  left: 50%;
  top: 95%;
  transform: translate(-50%, -50%);
  background-color: #444444f2;
  text-align: center;
  line-height: 50px;
  border-radius: 10px;
  border: 1px solid #d6d6d6;
}

.reset:hover {
  background-color: #353535f2;
}

#code-1 {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 20%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #525252bf;
  border-radius: 5px;
}

#code-2 {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #525252bf;
  border-radius: 5px;
}

#code-3 {
  height: 50px;
  width: 50px;
  position: fixed;
  left: 80%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #525252bf;
  border-radius: 5px;
}
<div class="content-size">
  <div class="picure-1-box">
    <div draggable="true" id="code-number-1" ondragstart="drag(event)">
      1
    </div>
  </div>
  <div class="picure-2-box">
    <div draggable="true" id="code-number-2" ondragstart="drag(event)">
      2
    </div>
  </div>
  <div class="picure-3-box">
    <div draggable="true" id="code-number-3" ondragstart="drag(event)">
      3
    </div>
  </div>
  <div class="picure-4-box">
    <div draggable="true" id="code-number-4" ondragstart="drag(event)">
      4
    </div>
  </div>
  <div class="picure-5-box">
    <div draggable="true" id="code-number-5" ondragstart="drag(event)">
      5
    </div>
  </div>
  <div class="picure-6-box">
    <div draggable="true" id="code-number-6" ondragstart="drag(event)">
      6
    </div>
  </div>
  <div class="picure-7-box">
    <div draggable="true" id="code-number-7" ondragstart="drag(event)">
      7
    </div>
  </div>
  <div class="picure-8-box">
    <div draggable="true" id="code-number-8" ondragstart="drag(event)">
      8
    </div>
  </div>
  <div class="picure-9-box">
    <div draggable="true" id="code-number-9" ondragstart="drag(event)">
      9
    </div>
  </div>
</div>
<div class="numbers-3">
  <div id="code-1" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
  <div id="code-2" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
  <div id="code-3" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
</div>
<div class="reset">
  <a href=".">Reset</a>
</div>

Upvotes: 2

Related Questions