By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How do I get this program to work the way I want it to? Think of prompt as both console.log & user input.


//can be run in chrome/edge console.
const QnA = {
0:`What number do you count first in coding?`,
1:`Jeff Bezos is CEO and President of which online retailer?`,
2:`Which social media app only lets you view pictures and messages for a limited time?`,
3:`What does a Geiger Counter measure?`,
4:`Which prestigious university did Microsoft founder Bill Gates drop out of?`,
5:`What year did the first Apple iPhone launch?`,
6:`What unit of length is equal to around 5.8 trillion miles?`,
answer6:`light year`,
7:`What does CPU stand for?`,
answer7:`central processing unit`,
8:`Created in 1990, what was the name of the first internet search engine?`,
9:`In which decade was the Sony Walkman launched?`,
10:`Was electronics company Nintendo founded in 1889, 1946 or 1975?`,
11:`From 2017 onwards, how many characters long can tweets be?`,
answer11:`280 characters`,
12:`What is the name of Elon Musk’s aerospace company?`,
13:`What were the duo who invented the aeroplane called together?`,
answer13:`the Wright Brothers`,
14:`What is the name of the classic 1972 arcade game based on table tennis?`,
15:`What does the term LASER stand for?`,
answer15:`light amplification by stimulated emission of radiation`,
16:`What does LG stand for in LG Electronics?`,
answer16:`lucky goldstar`,
17:`Solar power generates electricity from what source?`,
answer17:`the sun`,
18:`What is the name of the British computer scientist who invented the World Wide Web in 1989?`,
19:`Originally Amazon only sold which product?`,
20:`In what year was the first transatlantic radio broadcast?`,
let l = 0;
let e = 0;
let score;
let scori;
let xa;
let Qu = 0;
let answer;
let nam = prompt("what is your name?");
while (l == 0){
  if(isNaN(+nam) == false){
    nam = prompt(`Sorry, we don't accept [${nam}] as names what is your name?`);
  } else {
l = 0;
while(e == 0){
  Qu = prompt(`how many questions do you want to answer ${nam}? (1-5)`);
while (l == 0){
  if (isNaN(+Qu) || +Qu > 5 || +Qu < 1 || Qu == ''){
    Qu = prompt(`Sorry, ${nam} please use a digit between (and including) 1 and 5. How many questions do you want to answer?`);
  } else {
scori = Qu;
score = scori;
l = 0;
while (l <= Qu){
  xa = '' + Math.floor(Math.random()*21);
  answer = prompt(QnA.xa);
    if(answer.toLowerCase == QnA.answer+xa){
  } else {
l = 0;
while(l == 0){
  answer = prompt(`Congradulations you got ${score}/${scori} Would you like to play again ${nam}? Yes/No`);
  if(answer.toLowerCase == "yes"|| answer.toLowerCase == "y"|| answer.toLowerCase == "ye"){
  } else {
    if( answer.toLowerCase == "no" || answer.toLowerCase == "n"){
    } else {
      answer = prompt(`sorry ${nam} please answer with Yes or No not [${answer}]`);
Some help, but not all the answers:
Line 87 ->answer = prompt(QnA.xa);
S/B should be ->answer = prompt(QnA[xa]);

Line 88 ->
if (answer.toLowerCase == QnA.answer + xa) {
S/B ->f (answer.toLowerCase == QnA["answer" + xa]) {

Line 98 spelling error
S/B -> Congratulations t not d.

New Threads

Latest posts

Buy us a coffee!

Top Bottom