`#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=number_guess -t --no-align -c"
SECRET_NUMBER=$((RANDOM % 1000 + 1))
NUMBER_GUESSES=0
echo "Enter your username:"
read -r USERNAME
USERNAME_IN_DB=$($PSQL "SELECT username FROM users WHERE username = '$USERNAME'")
if [[ -n $USERNAME_IN_DB ]]; then
GAMES_PLAYED=$($PSQL "SELECT COUNT(*) FROM games WHERE user_id = (SELECT user_id FROM users WHERE username = '$USERNAME')")
BEST_GAME=$($PSQL "SELECT COALESCE(MIN(number_guesses), 0) FROM games WHERE user_id = (SELECT user_id FROM users WHERE username = '$USERNAME')")
echo "Welcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."
else
echo "Welcome, $USERNAME! It looks like this is your first time here."
$PSQL "INSERT INTO users (username) VALUES ('$USERNAME')"
fi
USER_ID=$($PSQL "SELECT user_id FROM users WHERE username = '$USERNAME'")
echo "Guess the secret number between 1 and 1000:"
while true; do
read -r GUESS
if [[ ! $GUESS =~ ^[0-9]+$ ]]; then
echo "That is not an integer, guess again:"
continue
fi
NUMBER_GUESSES=$((NUMBER_GUESSES + 1))
if ((GUESS < SECRET_NUMBER)); then
echo "It's higher than that, guess again:"
elif ((GUESS > SECRET_NUMBER)); then
echo "It's lower than that, guess again:"
else
$PSQL "INSERT INTO games (user_id, number_guesses) VALUES ($USER_ID, $NUMBER_GUESSES)"
echo "You guessed it in $NUMBER_GUESSES tries. The secret number was $SECRET_NUMBER. Nice job!"
break
fi
done
`
Hi, can anyone help me , I’ve been working on this for the past 3 days and keep on failing 2 tests :
FAILED TEST LOG
✘ SUBTASKS 1.1 :8 Your script should print the correct welcome message for returning users
Error: done() called multiple times in test <SUBTASKS 1.1 :8 Your script should print the correct welcome message for returning users> of file /home/codeally/project/.freeCodeCamp/test/1.1.test.js; in addition, done() received error: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(re.test(scriptOutput))
✘ SUBTASKS 1.1 :13 Your script should print the correct message when a game is finished
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(re.test(scriptOutput))
Here is my dump: `–
– PostgreSQL database dump
– Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
– Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = ‘UTF8’;
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config(‘search_path’, ‘’, false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
DROP DATABASE number_guess;
– Name: number_guess; Type: DATABASE; Schema: -; Owner: freecodecamp
CREATE DATABASE number_guess WITH TEMPLATE = template0 ENCODING = ‘UTF8’ LC_COLLATE = ‘C.UTF-8’ LC_CTYPE = ‘C.UTF-8’;
ALTER DATABASE number_guess OWNER TO freecodecamp;
\connect number_guess
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = ‘UTF8’;
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config(‘search_path’, ‘’, false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
SET default_tablespace = ‘’;
SET default_table_access_method = heap;
–
– Name: games; Type: TABLE; Schema: public; Owner: freecodecamp
CREATE TABLE public.games (
game_id integer NOT NULL,
user_id integer,
number_guesses integer
);
ALTER TABLE public.games OWNER TO freecodecamp;
–
– Name: games_game_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
CREATE SEQUENCE public.games_game_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.games_game_id_seq OWNER TO freecodecamp;
–
– Name: games_game_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
ALTER SEQUENCE public.games_game_id_seq OWNED BY public.games.game_id;
–
– Name: users; Type: TABLE; Schema: public; Owner: freecodecamp
CREATE TABLE public.users (
user_id integer NOT NULL,
username character varying
);
ALTER TABLE public.users OWNER TO freecodecamp;
–
– Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
CREATE SEQUENCE public.users_user_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.users_user_id_seq OWNER TO freecodecamp;
–
– Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;
–
– Name: games game_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
ALTER TABLE ONLY public.games ALTER COLUMN game_id SET DEFAULT nextval(‘public.games_game_id_seq’::regclass);
–
– Name: users user_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval(‘public.users_user_id_seq’::regclass);
–
– Data for Name: games; Type: TABLE DATA; Schema: public; Owner: freecodecamp
INSERT INTO public.games VALUES (1, 1, 5);
INSERT INTO public.games VALUES (2, 12, 53);
INSERT INTO public.games VALUES (3, 13, 3);
–
– Data for Name: users; Type: TABLE DATA; Schema: public; Owner: freecodecamp
INSERT INTO public.users VALUES (1, ‘Ana’);
INSERT INTO public.users VALUES (2, ‘user_1685012041999’);
INSERT INTO public.users VALUES (3, ‘user_1685012041998’);
–
– Name: games_game_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
SELECT pg_catalog.setval(‘public.games_game_id_seq’, 383, true);
–
– Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
SELECT pg_catalog.setval(‘public.users_user_id_seq’, 152, true);
–
– Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
ALTER TABLE ONLY public.games
ADD CONSTRAINT games_pkey PRIMARY KEY (game_id);
–
– Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);
–
– Name: users users_username_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_username_key UNIQUE (username);
–
– Name: games games_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
ALTER TABLE ONLY public.games
ADD CONSTRAINT games_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(user_id);
–
– PostgreSQL database dump complete
`