Skip to content

Instantly share code, notes, and snippets.

@colevandersWands
Last active May 9, 2024 20:25
Show Gist options
  • Save colevandersWands/53e0aba57d7c6602c2b63c9b16789d98 to your computer and use it in GitHub Desktop.
Save colevandersWands/53e0aba57d7c6602c2b63c9b16789d98 to your computer and use it in GitHub Desktop.
generated cat detector drafts for tutorial
#!/bin/bash
while true; do
read -p "Please input the word \"cat\": " input
if [ "$input" != "cat" ]; then
echo "Incorrect input. Please try again."
else
echo "Congratulations! You entered \"cat\"."
break
fi
done
<!DOCTYPE html>
<html>
<head>
<title>Cat Input</title>
</head>
<body>
<script>
function promptForCat() {
const userInput = prompt('Please input the word "cat":');
if (userInput?.trim().toLowerCase() !== 'cat') {
alert('Incorrect input. Please try again.');
promptForCat();
} else {
alert('Congratulations! You entered "cat".');
}
}
promptForCat();
</script>
</body>
</html>
#include <stdio.h>
#include <string.h>
int main() {
char input[10];
while (1) {
printf("Please input the word \"cat\": ");
scanf("%s", input);
if (strcmp(input, "cat") != 0) {
printf("Incorrect input. Please try again.\n");
} else {
printf("Congratulations! You entered \"cat\".\n");
break;
}
}
return 0;
}
using System;
class Program
{
static void Main()
{
while (true)
{
Console.Write("Please input the word \"cat\": ");
string input = Console.ReadLine().Trim().ToLower();
if (input != "cat")
{
Console.WriteLine("Incorrect input. Please try again.");
}
else
{
Console.WriteLine("Congratulations! You entered \"cat\".");
break;
}
}
}
}
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func promptForCat() {
for {
fmt.Print("Please input the word \"cat\": ")
inputReader := bufio.NewReader(os.Stdin)
input, _ := inputReader.ReadString('\n')
input = strings.TrimSpace(strings.ToLower(input))
if input != "cat" {
fmt.Println("Incorrect input. Please try again.")
} else {
fmt.Println("Congratulations! You entered \"cat\".")
break
}
}
}
func main() {
promptForCat()
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("Please input the word \"cat\": ");
String input = scanner.nextLine().trim().toLowerCase();
if (!input.equals("cat")) {
System.out.println("Incorrect input. Please try again.");
} else {
System.out.println("Congratulations! You entered \"cat\".");
break;
}
}
scanner.close();
}
}
(defun prompt-for-cat ()
(loop
(format *query-io* "Please input the word \"cat\": ")
(finish-output)
(let ((input (read-line)))
(if (string/= (string-trim " " input) "cat")
(format t "Incorrect input. Please try again.~%")
(progn
(format t "Congratulations! You entered \"cat\".~%")
(return))))))
(prompt-for-cat)
import readline from 'readline';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function promptForCat() {
while (true) {
const answer = await rl.question('Please input the word "cat": ');
if (answer.trim().toLowerCase() === 'cat') {
console.log('Congratulations! You entered "cat".');
rl.close();
break;
} else {
console.log('Incorrect input. Please try again.');
}
}
}
await promptForCat();
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function promptForCat() {
rl.question('Please input the word "cat": ', (answer) => {
if (answer.trim().toLowerCase() !== 'cat') {
console.log('Incorrect input. Please try again.');
promptForCat();
} else {
console.log('Congratulations! You entered "cat".');
rl.close();
}
});
}
promptForCat();
def prompt_for_cat():
while True:
user_input = input('Please input the word "cat": ').strip().lower()
if user_input != 'cat':
print('Incorrect input. Please try again.')
else:
print('Congratulations! You entered "cat".')
break
prompt_for_cat()
def prompt_for_cat
loop do
print "Please input the word \"cat\": "
input = gets.chomp.strip.downcase
if input != "cat"
puts "Incorrect input. Please try again."
else
puts "Congratulations! You entered \"cat\"."
break
end
end
end
prompt_for_cat
use std::io;
fn main() {
loop {
println!("Please input the word \"cat\":");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
let input = input.trim().to_lowercase();
if input != "cat" {
println!("Incorrect input. Please try again.");
} else {
println!("Congratulations! You entered \"cat\".");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment