S
S
Steve2018-10-01 22:57:27
Arrays
Steve, 2018-10-01 22:57:27

Is it possible to access an associative array like this?

In general, you need to write a program that, according to the entered character, gives out its name. For example, if the character '*' is entered, the program should output the word "asterisk". The program must recognize 10 different characters in this way. I tried to do it through an associative array but something went wrong

var symb = {
  "*" : 'Звездочка',
  "%" : 'Процент',
  "." : 'Точка',
  "-" : 'Минус',
  "?" : 'вопросительный знак',
  ";" : 'Точка с запятой',
  "№" : 'Номер',
  "!" : 'Восклицательный знак',
  "," : 'Запятая',
  ":" : 'Двоеточие',

};
var v;
for (var i=0; v!=0; i++){
v = eval( prompt( "Введите знак или 0 чтобы закончить: ", "symbol"));
console.log(symb.v);	
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2018-10-01
Gorton

for (var i=0; v!=0; i++){
v = prompt( "Введите знак или 0 чтобы закончить: ", "symbol");
console.log(symb[v]);	
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question