Skip to content
Sign UpLog In
Profile icon

LlamaBoii

@LlamaBoii
Repls
Community
LlamaBoii
LlamaBoii
published an Update
1 year ago
0
game
game
How to add audio to html game?
So I have this simple game, It's like Chrome Dino Game. So I wanted to make it so that everytime I jump it plays a audio. I know how to add audio (like ` for HTML, and play.song` or whatever for Javascript) But I don't know where to add it or How do I make it automatically play the audio when everytime I jump. Can someone look at my repl and tell me how and where do I do it please? Edit: Also if you could can you tell me how do i make the character a bit more in the middle (not completely) I don't really need character to be in middle but if you know tell me, if not, it's completely fine Thanks.
MattDESTROYER
MattDESTROYER
@LlamaBoii You can just use: ```js const audioOrSound = new Audio("filename.mp3"); audioOrSound.play(); ``` You can look [here](https://stackoverflow.com/questions/9419263/how-to-play-audio) for more.1 year ago
LlamaBoii
LlamaBoii
published an Update
1 year ago
4
Help with Python calculator
So basically what this repl is for like doing simple math stuff. So i want to know, after everytime someone does a problem let's say addition, 1+1, they get 2. so once after they've done it i want it to ask like type anything to start a new calculation and after they've typed anything it basically starts everything over so they can do a different calculation. How to do so?
LlamaBoii
LlamaBoii
@TheRealThisas yea so i tried the ``` exitFlag = False while exitFlag == False: """ Code """ isExit = input("Type anything to start a new calculation or 'exit' to exit.") if isExit == "exit": exitFlag = True ``` and as soon as i run it it just loops it and spams the console.. did i do something wrong? if you want you can check the repl (it's the same one above)1 year ago
TheRealThisas
TheRealThisas
@LlamaBoii The problem is with indentation. In your code the loop is not implemented properly as the rest of your code is not in the loop. ```python3 from getkey import getkey, keys exitFlag = False while exitFlag == False: print("what you wanna do?") print(" ") print("Type + for addition") print("Type - for subtraction") print("Type * for multiplication") print("Type / for division") op = input('Enter your choice here = ') if op == '+' : num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number here: ")) add = num1 + num2 print("{0} + {1} is {2}".format(num1, num2, add)) elif op == '-' : num1 = float(input("Enter the first number here: ")) num2 = float(input("Enter the second number here: ")) sub = num1 - num2 print("{0} - {1} is {2}".format(num1, num2, sub)) elif op == '*' : num1 = float(input("Enter the first number here: ")) num2 = float(input("Enter te second number here: ")) multi = num1 * num2 print("{0} * {1} is {2}".format(num1, num2, multi)) elif op == '/' : num1 = float(input("Enter the first number here: ")) num2 = float(input("Enter the second number here: ")) division = num1 / num2 print("{0} / {1} is {2}".format(num1, num2, division)) else : print("something went wrong ") print("Type anything to start a new calculation or ESC to exit.") isExit = getkey() if isExit == keys.ESCAPE: exitFlag = True ``` In the above code block is a proper implementation of the while loop. Further, I have taken the liberty of adding @Dunce 's suggestion as I think it is what you're looking for. Take note however that this code can be significantly improved. ```python3 from getkey import getkey, keys def main(): # Ask the user for first number and second number. first_number = input("Enter first number: ") second_number = input("Enter second number: ") # Ask what calculation needs to be done. calculation = input("Enter calculation: ") # Print the calculation performed with the answer. if calculation == "+": print(f"{first_number} + {second_number} = {int(first_number) + int(second_number)}") elif calculation == "-": print(f"{first_number} - {second_number} = {int(first_number) - int(second_number)}") elif calculation == "*": print(f"{first_number} * {second_number} = {int(first_number) * int(second_number)}") elif calculation == "/": print(f"{first_number} / {second_number} = {int(first_number) / int(second_number)}") else: print("Invalid calculation.") if __name__ == "__main__": killStatus = False while killStatus == False: main() userInput = getkey() if userInput == keys.Q or userInput == keys.q: killStatus = True else: killStatus = False ``` If you plan on expanding the program for more than simple calculations consider using functions. ```python3 def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): return x / y def calculate(x, y): print("{} + {} = {}".format(x, y, add(x, y))) print("{} - {} = {}".format(x, y, subtract(x, y))) print("{} * {} = {}".format(x, y, multiply(x, y))) print("{} / {} = {}".format(x, y, divide(x, y))) def main(): while True: try: x = int(input("Enter a number: ")) y = int(input("Enter another number: ")) calculate(x, y) except ValueError: print("Please enter a number.") except ZeroDivisionError: print("Please enter a number other than zero.") except: print("An unknown error occurred.") else: break if __name__ == "__main__": main() ``` Hope this works, Thisas1 year ago
PreciousOgunley
PreciousOgunley
@LlamaBoii dude i thought you were smart1 year ago
LlamaBoii
LlamaBoii
shared a Post
1 year ago
I'm trying to make a website where I want the text to show my roles and change it every 2 seconds automatically. Where it shows my [roles] for example
Coder100
Coder100
use setInterval to make the interval, and use HTML to change it. I recommend using span tags, like this: I'm a Coder whatever And for your js code: let i = 0; let names = ["Coder", "Programmer", "Troller"]; function change() { document.querySelectorAll(".my-role").forEach(el => el.innerHTML = names[i]); i++; i %= names.length; } change(); setInterval(change, 2 * 1000); A working repl: https://replit.com/@Coder100/SuperiorPlaintiveDebuggers-landing-page-carousel#script.js1 year ago
NFadhlurrahman
NFadhlurrahman
In the script.js file, write the following code: let heading = document.querySelector("h1"); setInterval(() => { if (heading.innerText == "I'm a YouTuber") { heading.innerText = "I'm a developer"; } else { heading.innerText = "I'm a YouTuber"; } }, 2000);1 year ago