🎮ArcadeLab

Smart Wikipedia AI

by SonicBear35
103 lines1.8 KB
▶ Play
<!DOCTYPE html>
<html>
<head>
<title>Smart Wikipedia AI</title>
<style>
body {
  font-family: Arial;
  background: #111;
  color: white;
  text-align: center;
}

#box {
  width: 90%;
  height: 350px;
  margin: auto;
  background: #222;
  overflow: auto;
  padding: 10px;
  text-align: left;
}

input {
  width: 70%;
  padding: 10px;
}

button {
  padding: 10px;
}
</style>
</head>
<body>

<h2>🤖 Smart Wikipedia AI</h2>

<div id="box"></div>

<input id="input" placeholder="Type: football / nigeria / space" />
<button onclick="search()">Search</button>

<script>
function add(text){
  document.getElementById("box").innerHTML += "<div>"+text+"</div>";
}

function search(){
  let query = document.getElementById("input").value.trim();
  add("You: " + query);

  if(!query){
    add("AI: type something ❌");
    return;
  }

  wikiAI(query);
}

// 🌐 SMART WIKIPEDIA FUNCTION
async function wikiAI(query){

  try {
    let url = `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(query)}`;
    
    let res = await fetch(url);

    if(!res.ok){
      throw new Error("Not found");
    }

    let data = await res.json();

    if(data.extract){
      add("AI 🌐: " + data.extract);
    } else {
      fallback(query);
    }

  } catch (e) {
    fallback(query);
  }
}

// 📴 OFFLINE / FALLBACK MODE
function fallback(query){

  let offline = {
    football: "Football is a sport played with a ball between two teams ⚽",
    nigeria: "Nigeria is a country in West Africa 🌍",
    space: "Space is the universe outside Earth 🚀",
    earth: "Earth is the planet we live on 🌍"
  };

  if(offline[query.toLowerCase()]){
    add("AI 📴: " + offline[query.toLowerCase()]);
  } else {
    add("AI: No internet, and no offline data found ❌");
  }
}
</script>

</body>
</html>

Game Source: Smart Wikipedia AI

Creator: SonicBear35

Libraries: none

Complexity: moderate (103 lines, 1.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: smart-wikipedia-ai-sonicbear35" to link back to the original. Then publish at arcadelab.ai/publish.