Last active
May 9, 2024 20:25
-
-
Save colevandersWands/53e0aba57d7c6602c2b63c9b16789d98 to your computer and use it in GitHub Desktop.
generated cat detector drafts for tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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