Skip to content

Commit

Permalink
Added Random Word Generator Calculator (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhevamuthu authored Jun 5, 2024
1 parent b02421f commit 939d3f4
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Calculators/Random-Word-Generator-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Random Word Generator Calculator</p>

## Description :-

This is a calculator that generates random words based on a specified starting letter and the desired number of words.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/78e57adb-0f79-4a4d-8cbe-20484b886b38)
22 changes: 22 additions & 0 deletions Calculators/Random-Word-Generator-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Random Word Generator Calculator</title>
</head>
<body>
<div class="container">
<h1>Random Word Generator</h1>
<label for="start-letter">Enter starting letter:</label>
<input type="text" id="start-letter">
<label for="word-count">Enter number of words:</label>
<input type="number" id="word-count" min="1" value="1">
<button onclick="generateWords()">Generate</button>
</div>
<div id="result-container" class="result-container"></div>

<script src="script.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions Calculators/Random-Word-Generator-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function generateWords() {
var startLetter = document.getElementById("start-letter").value.toLowerCase();
var wordCount = document.getElementById("word-count").value;

var apiUrl = "https://random-word-api.vercel.app/api?words=" + wordCount + "&letter=" + startLetter;

fetch(apiUrl)
.then(response => response.json())
.then(data => {
var resultContainer = document.getElementById("result-container");
resultContainer.innerHTML = "";
data.forEach((word, index) => {
var wordBox = document.createElement("div");
wordBox.className = "word-box";
wordBox.textContent = word;
resultContainer.appendChild(wordBox);
});

// Clear the input fields
document.getElementById("start-letter").value = "";
document.getElementById("word-count").value = "1";
})
.catch(error => {
console.error("Error fetching random words:", error);
document.getElementById("result-container").textContent = "Failed to generate words. Please try again.";
});
}
91 changes: 91 additions & 0 deletions Calculators/Random-Word-Generator-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(to right, #ff7e5f, #feb47b);
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}

.container {
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
width: 500px;
background-image: url('https://img.freepik.com/free-vector/hand-drawn-abc-background_23-2150598241.jpg');
border: 5px solid black;
}

h1 {
font-family: 'Verdana', sans-serif;
background: linear-gradient(to right, blue, #a510d1);
-webkit-background-clip: text;
color: transparent;
margin-bottom: 20px;
}

label {
display: block;
margin-top: 10px;
font-size: 16px;
color: black;
font-weight: bolder;
}

input[type="text"], input[type="number"] {
width: calc(100% - 20px);
padding: 10px;
margin-top: 5px;
border: 1px solid #cccccc;
border-radius: 5px;
box-sizing: border-box;
}

button {
margin-top: 15px;
padding: 10px 20px;
background-color: #15dfea;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
}

input[type="text"] {
margin-bottom: 45px; /* Add this line */
}

button:hover {
background-color: #3815bc;
}

.result-container {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
padding: 10px;
background: linear-gradient(to right, #4facfe, #00f2fe);
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
width: calc(100% - 40px);
}

.word-box {
background-color: white;
color: black;
padding: 10px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
width: 100px;
text-align: center;
font-family: 'Courier New', Courier, monospace;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,20 @@ <h3>Generates randomized English alphabets used in brain teaser activities.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Random Word Generator Calculator</h2>
<h3>Generates random words based on a specified starting letter and the desired number of words.</h3>
<div class="card-footer">
<a href="./Calculators/Random-Word-Generator-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Random-Word-Generator-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Ratio Calculator</h2>
Expand Down

0 comments on commit 939d3f4

Please sign in to comment.