🎮ArcadeLab

LinguaGo

by BoldPenguin14
457 lines6.8 KB
▶ Play

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>LinguaGo</title>

<style>
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  background: #f5f5f5;
  text-align: center;
  margin: 0;
}

header {
  background: #58cc02;
  color: white;
  padding: 20px;
  font-size: 28px;
  font-weight: bold;
}

.stats {
  font-size: 20px;
  padding: 12px;
}

.card {
  background: white;
  padding: 20px;
  margin: 20px auto;
  max-width: 420px;
  width: 92%;
  border-radius: 18px;
  box-shadow: 0 3px 10px #ddd;
}

button, select {
  width: 100%;
  padding: 14px;
  margin: 6px 0;
  border: 2px solid #ddd;
  border-radius: 12px;
  background: white;
  font-size: 16px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.7;
  cursor: default;
}

.green {
  background: #58cc02;
  color: white;
  border: 0;
  font-weight: bold;
}

.word {
  font-size: 38px;
  color: #58cc02;
  margin: 25px 0;
  overflow-wrap: anywhere;
}

.correct {
  color: #58cc02;
  font-weight: bold;
  font-size: 19px;
}

.wrong {
  color: #ff4b4b;
  font-weight: bold;
  font-size: 18px;
}

.progress {
  height: 12px;
  background: #ddd;
  border-radius: 20px;
  margin: 15px 0;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 0%;
  background: #58cc02;
  transition: width .3s;
}

</style>
</head>

<body>

<header>🦉 LinguaGo</header>

<div class="stats">
⭐ <span id="xp">0</span> XP
&nbsp; | &nbsp;
❤️ <span id="hearts">5</span>
</div>

<div class="card" id="app">

<h2>🌍 Choose your language</h2>

<select id="language">
<option>Russian</option>
<option>Spanish</option>
<option>French</option>
<option>German</option>
<option>Japanese</option>
</select>

<button class="green" onclick="start()">
START LEARNING
</button>

</div>

<script>

const courses = {

Russian: [
["Привет","Hello"],
["Спасибо","Thank you"],
["Вода","Water"],
["Друг","Friend"],
["Да","Yes"],
["Нет","No"],
["Мама","Mom"],
["Папа","Dad"],
["Книга","Book"],
["Дом","House"]
],

Spanish: [
["Hola","Hello"],
["Gracias","Thank you"],
["Agua","Water"],
["Amigo","Friend"],
["Sí","Yes"],
["No","No"],
["Madre","Mother"],
["Padre","Father"]
],

French: [
["Bonjour","Hello"],
["Merci","Thank you"],
["Eau","Water"],
["Ami","Friend"],
["Oui","Yes"],
["Non","No"]
],

German: [
["Hallo","Hello"],
["Danke","Thank you"],
["Wasser","Water"],
["Freund","Friend"],
["Ja","Yes"],
["Nein","No"]
],

Japanese: [
["こんにちは","Hello"],
["ありがとう","Thank you"],
["水","Water"],
["友達","Friend"],
["はい","Yes"],
["いいえ","No"]
]

};

let words = [];
let learned = 0;
let lesson = 1;
let index = 0;
let xp = 0;
let hearts = 5;
let selected = "";
let correct = "";
let answered = false;

const app = document.getElementById("app");

function start() {

  words = courses[document.getElementById("language").value];

  learned = 0;
  lesson = 1;
  index = 0;
  xp = 0;
  hearts = 5;

  update();
  next();

}

function update() {

  document.getElementById("xp").textContent = xp;
  document.getElementById("hearts").textContent = hearts;

}

function next() {

  if (learned >= words.length) {

    app.innerHTML = `
      <h1>🏆 Course completed!</h1>
      <h2>🎉 Amazing job!</h2>
      <p>You learned all ${words.length} words!</p>
      <h2>⭐ ${xp} XP earned</h2>
      <button class="green" onclick="start()">
        PLAY AGAIN
      </button>
    `;

    return;
  }

  index = learned;

  let w = words[index];

  let progress = (learned / words.length) * 100;

  app.innerHTML = `

    <h2>Lesson ${lesson}</h2>

    <div class="progress">
      <div class="bar" style="width:${progress}%"></div>
    </div>

    <p>New word ${index + 1} of ${words.length}</p>

    <div class="word">${w[0]}</div>

    <h2>${w[1]}</h2>

    <p>Learn this word before your quiz!</p>

    <button onclick="speak()">
      🔊 Listen
    </button>

    <button class="green" onclick="quiz()">
      I LEARNED THIS!
    </button>

  `;

}

function speak() {

  let codes = {
    Russian: "ru-RU",
    Spanish: "es-ES",
    French: "fr-FR",
    German: "de-DE",
    Japanese: "ja-JP"
  };

  let language = document.getElementById("language").value;

  let speech = new SpeechSynthesisUtterance(words[index][0]);

  speech.lang = codes[language];

  speechSynthesis.speak(speech);

}

function quiz() {

  selected = "";
  answered = false;

  correct = words[index][1];

  let pool = words.slice(0, learned + 1);

  let options = [...new Set(pool.map(w => w[1]))];

  while (options.length < Math.min(learned + 2, words.length)) {

    let extra = words.find(w => !options.includes(w[1]));

    if (!extra) break;

    options.push(extra[1]);

  }

  options.sort(() => Math.random() - 0.5);

  app.innerHTML = `

    <h2>📝 Lesson ${lesson} Quiz</h2>

    <p>What does this word mean?</p>

    <div class="word">${words[index][0]}</div>

    <div id="choices"></div>

    <p id="result"></p>

    <button class="green" id="checkButton" onclick="check()">
      CHECK ANSWER
    </button>

  `;

  let choices = document.getElementById("choices");

  options.forEach(answer => {

    let b = document.createElement("button");

    b.textContent = answer;

    b.onclick = () => {

      if (answered) return;

      selected = answer;

      document.querySelectorAll("#choices button").forEach(btn => {
        btn.style.borderColor = "#ddd";
      });

      b.style.borderColor = "#58cc02";

    };

    choices.appendChild(b);

  });

}

function check() {

  if (answered) return;

  let result = document.getElementById("result");

  if (!selected) {

    result.textContent = "⚠️ Choose an answer first!";
    result.className = "wrong";

    return;

  }

  if (selected === correct) {

    answered = true;

    xp += 10;

    update();

    result.textContent = "🎉 Correct! +10 XP";

    result.className = "correct";

    document.querySelectorAll("#choices button").forEach(btn => {
      btn.disabled = true;

      if (btn.textContent === correct) {
        btn.style.borderColor = "#58cc02";
      }
    });

    document.getElementById("checkButton").remove();

    let nextButton = document.createElement("button");

    nextButton.className = "green";

    nextButton.textContent = "CONTINUE ➜";

    nextButton.onclick = () => {

      learned++;

      lesson++;

      next();

    };

    app.appendChild(nextButton);

  } else {

    hearts--;

    update();

    result.textContent = "❌ Incorrect! Try again!";

    result.className = "wrong";

    selected = "";

    document.querySelectorAll("#choices button").forEach(btn => {
      btn.style.borderColor = "#ddd";
    });

    if (hearts <= 0) {

      app.innerHTML = `

        <h1>❤️ Out of hearts!</h1>

        <p>Don't give up! Try again.</p>

        <button class="green" onclick="start()">
          RESTART COURSE
        </button>

      `;

    }

  }

}

</script>

</body>
</html>

Game Source: LinguaGo

Creator: BoldPenguin14

Libraries: none

Complexity: complex (457 lines, 6.8 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: linguago-boldpenguin14" to link back to the original. Then publish at arcadelab.ai/publish.