Jump to content

Cool Idea for Dictionary


brooke_theperson
 Share

Recommended Posts

Hey, so I just finished the basics of a simple program I have made to translate some Spanish vocab. After completing all the functions, I realized how long it would take to create a complete dictionary containing all the vocab that I learn in Spanish class. I would have to enter everything in both a spanish and an english dictionary. What I would like to do is create a button that when clicked comes up with a prompt.This would be the easy part, that I know how to do. The hard part is this: I want a function that enters whatever I type into the prompt as a word in the dictionary.

Here is how my dictionaries are set up:

 

 

var translation = {};// Spanish dictionarytranslation.spanish = {};translation.spanish["gato"] = "cat";translation.spanish["perro"] = "dog";translation.spanish["hola"] = "hello";// English dictionarytranslation.english = {};translation.english["cat"] = "gato";translation.english["dog"] = "perro";translation.english["hello"] = "hola";

 

The button looks like this:

 

 

<button class = "NewWord"onclick="newWord()">            Add to Dictionary        </button>

 

This is the prompt:

 

 

function newWord(){    var word = prompt("Add a new word to the dictionary.");}

 

I thought it would be cool if I could click the button, and in the prompt I could type, "libro, book" and in the spanish dictionary it would enter a word that looked like this:

translation.spanish["libro"] = "book";
.Also, in the english dictionary a new word would enter and it would look like this:
translation.english["book"] = "libro";

 

I was wondering, is there any way that this would work? If I could get a few ideas on how to do this that would be great. Like I have said before, I am a newbie, so this is all kind of a learning experience. If I could get some help that would be great. Thanks so much!

Link to comment
Share on other sites

This is the sort of project that requires a database, which would require a server-side language. Javascript can't save information on its own.

 

You could have Javascript add elements to the array, but as soon as you leave the page all the information would disappear and at no point would it be available to anybody else but you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...