Day 091 - Project 91 : The joke's on you!

If you have any questions, comments or issues with this project please post them here!

Hey Guys! I have broken some code for you… Can you please fix it?
Haha :crazy_face:

Now, seriously, here’s my problem:

I get an interesting ValueError: Circular Reference detected when trying to store the joke to the replit database.

I know it’s probably because of my functions, but I don’t see, why it shouldn’t work…

Can you please enlighten me? :pray:

import requests, json
from replit import db

def joke():  
  result = requests.get("https://icanhazdadjoke.com/", headers={"Accept":"application/json"}) 
  joke = result.json()["joke"]
  id = result.json()["id"]
  print(joke)
  return joke, id

def save(joke, id):
  db[id] = joke
  print("Joke saved")
  return

def view():
  for key in db.keys():
    print(f"{key}\n\n")

def menu():
  print("The Joke's on You!\n")
  select = input("Generate random Joke or view Joke-Database?\n1: Random Joke\n2:View Jokes\n")
  if select == "1":
    joke()
    store = input("Save this Joke?\nYes/No:\t").lower()
    if store[0] == "y":
      save(joke,id)
  if select == "2":
    view()
  select = input("press enter when done")
  return
    
while True:
  menu()
  

Thanks :kissing_closed_eyes:

You have a var passed to a function called “joke”, and you have a function called “joke”, try renaming one or the other.
Here:

And here:

1 Like

Thank You @Firepup650 ! - too easy :sweat_smile: :sweat_smile: