首页 > 解决方案 > ReferenceError:$ 未在 /code.js 10:1 中定义

问题描述

我正在尝试使用 JavaScript 和 jQuery 制作一个生活模拟器(基于 Web),当我获取代码并运行它时,控制台说在我添加此代码之前ReferenceError: '$' is not defined at /code.js 10:1jQuery工作:我不知道问题是什么。这是我的代码:$$('#name').html(name);

var name = prompt('What is your name?');
var money = 1000;
var hunger = 100;
var hygiene = 100;
var sleep = 100;
var favColor = prompt('What is your favorite color?\nIf there is 2 words, combine them.\nDo not capitalize the color.', 'green');

var start = true;

$('#name').html(name);
$('#color').css('color', favColor);

function bed() {
    $('#bed').html('You are sleeping');
    var sleeping = setInterval(function() {
        if (sleep == 100) {
            this.clearInterval();
            $('#bed').html('You are awake');
        } else {
            sleep++;
        }
    }, 500);
}

标签: javascriptjquery

解决方案


在代码的标题部分添加 jQuery。


推荐阅读