Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use-strict'
- var dictionary = {};
- function addValues(){
- var llave = document.getElementById("llave").value;
- var valor = document.getElementById("valor").value;
- dictionary[llave] = valor;
- }
- function printJSON(){
- var string = '{<br>"diccionario":[<br>'
- for(var llave in dictionary){
- var valor = dictionary[llave];
- var tipo = "String";
- if(!isNaN(valor)){
- tipo = "Number";
- }else if(valor=="true"||valor=="false"){
- tipo = "Bool";
- }
- string += '{"llave":"'+llave+'",<br>"valor":"'+valor+'",<br>"tipo":"'+tipo+'"},<br>';
- }
- string = string.slice(0,string.length-5);
- string += "<br>";
- string += ' ]<br>}'
- document.getElementById("format").innerHTML=string;
- }
- function printXML(){
- var string = '<dictionary><br>'
- for(var llave in dictionary){
- var valor = dictionary[llave];
- var tipo = "String";
- if(!isNaN(valor)){
- tipo = "Number";
- }else if(valor=="true"||valor=="false"){
- tipo = "Bool";
- }
- string += '<element><br>';
- string += '<llave>'+llave+'</llave><br>';
- string += '<tipo>'+tipo+'</tipo><br>';
- string += '<valor>'+valor+'</valor><br>';
- string += '</element><br>';
- }
- string += '</dictionary>'
- document.getElementById("format").innerHTML=string;
- }
- window.onload = function(){
- var button = document.getElementById("Add");
- button.addEventListener("click",addValues);
- };
Add Comment
Please, Sign In to add comment