wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
var num int = 'message' | var num string = 'message' | Type mismatch. | Go |
[30, 8, 58 | [30, 8, 58] | Close bracket. | Ruby |
b == '30' | b === 30 | Use strict equality. | JavaScript |
WHERE status = '13' | WHERE status = 13 | Don't quote integer. | SQL |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
.Product {{ color: blue; }} | .Product {{ color: blue; }} | Correct. | CSS |
let data = 58; data += 1; | let mut data = 58; data += 1; | Need mut to modify. | Rust |
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
let count: number = 'output'; | let count: string = 'output'; | Fix type. | TypeScript |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(91); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(91, () => console.log('listening')); | Add callback. | Node.js |
function compute(index:string){{return index;}} compute(5); | function compute(index:string){{return index;}} compute('info'); | Pass correct type. | TypeScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
arr[22] | if (length(arr) >= 22) arr[22] | Check length. | R |
val bar = 71; bar = 18 | var bar = 71; bar = 18 | Use var for reassignment. | Scala |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
b > 52 & b < 80 | b > 52 and b < 80 | Use 'and' not '&'. | Python |
if y = 12 {{}} | if y == 12 {{}} | Use ==. | Swift |
class Order {{ int bar; }}; | class Order {{ public: int bar; }}; | Make public. | C++ |
Write-Host 'message' | Write-Host 'message' | Correct. | PowerShell |
let item = 'result' | let item = "result" | Double quotes. | Swift |
<user><age>info</age><age>64</age></user | <user><age>info</age><age>64</age></user> | Add closing >. | XML |
let vec=vec![55,11,54]; let primary=&vec[0]; vec.push(48); | let mut vec=vec![55,11,54]; let primary=vec[0]; vec.push(48); | Copy instead of reference. | Rust |
let temp: Int = 'data' | let temp: String = 'data' | Fix type. | Swift |
if num > 58
print('value') | if num > 58:
print('value') | Colon missing after if. | Python |
'info' + 69 | 'info' + str(69) | Can't add int to string. | Python |
name: data
age: 43 | name: data
age: 43 | Correct. | YAML |
{{"id":"test",}} | {{"id":"test"}} | Remove trailing comma. | JSON |
let a = 62; let a = 8; | let a = 62; a = 8; | Duplicate declaration. | JavaScript |
'29' + 77 | 29 + 77 | Avoid string coercion. | JavaScript |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
p {{ color: green }} | p {{ color: green; }} | Add semicolon. | CSS |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
if (num = 61) | if (num == 61) | Use ==. | Scala |
void main() {{ print('value') }} | void main() {{ print('value'); }} | Add semicolon. | Dart |
System.out.println('info') | System.out.println('info'); | Add semicolon. | Java |
71a = 10 | a71 = 10 | Variable cannot start with digit. | Python |
print('message') | print('message') | Correct. | R |
let str1 = String::from("result"); let s2 = str1; println!("{{}}", str1); | let str1 = String::from("result"); let s2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
String num = 'world'; | String num = "world"; | Double quotes. | Java |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
<center>info</center> | <div style='text-align:center;'>info</div> | Use CSS. | HTML |
'world' + 77 | 'world' + str(77) | Can't add int to string. | Python |
while a > 92
a -= 1 | while a > 92:
a -= 1 | Colon missing after while. | Python |
index = message | index = 'message' | Quote strings. | Python |
["value", 73] | ["value", 73] | Correct. | JSON |
{{'title':'value'}} | {{"title":"value"}} | Use double quotes. | JSON |
values[81] | if (length(values) >= 81) values[81] | Check length. | R |
switch(c){{ case 18: break; }} | switch(c){{ case 18: break; default: break; }} | Add default case. | Java |
<table><tr><td>data<td>world</tr></table> | <table><tr><td>data</td><td>world</td></tr></table> | Close td. | HTML |
[27, 76, 49 | [27, 76, 49] | Close bracket. | Ruby |
if count = 40 | if count == 40 | Use ==. | Go |
cin >> foo
cout << foo; | cin >> foo;
cout << foo; | Add semicolon. | C++ |
if bar > 8
print('hello') | if bar > 8:
print('hello') | Colon missing after if. | Python |
items(22) | if length(items) >= 22, items(22), end | Check length. | MATLAB |
for b in range(59)
print(b) | for b in range(59):
print(b) | Colon after for. | Python |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
<img src='value.jpg'> | <img src='value.jpg' alt='desc'> | Add alt text. | HTML |
if (temp = 58) | if (temp == 58) | Use ==. | C++ |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
y > 23 & z < 29 | y > 23 and z < 29 | Use 'and' not '&'. | Python |
String name = 'output'; | String name = 'output'; | Correct. | Dart |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(53); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(53, () => console.log('listening')); | Add callback. | Node.js |
if c = 12 {{}} | if c == 12 {{}} | Use ==. | Swift |
List(62,77,81) | List(62,77,81) | Correct. | Scala |
print('world') | print('world') | Correct. | R |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
echo output world | echo 'output world' | Quote to prevent splitting. | Shell |
def bar():
print('test') | def bar():
print('test') | Indent function body. | Python |
print 'hello' | print 'hello'; | Add semicolon. | Perl |
$data[91] | if ($data.Count -gt 91) {{ $data[91] }} | Check bounds. | PowerShell |
jwt.sign({{id:7}}, 'password'); | jwt.sign({{id:7}}, 'password', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
let b: number | null = null; b.toFixed(72); | let b: number | null = null; if(b!==null) b.toFixed(72); | Null check. | TypeScript |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
void bar();
int main(){{bar();}} | void bar(); // prototype
int main(){{bar();}} | Declare before use. | C++ |
if foo = 75 then
print('message')
end | if foo == 75 then
print('message')
end | Use ==. | Lua |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
if data = 92 | if data == 92 | Use ==. | Ruby |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
WHERE age = '87' | WHERE age = 87 | Don't quote integer. | SQL |
id: value
age: world, | id: value
age: world | Remove comma. | YAML |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
local z = 28 | local z = 28 | Correct. | Lua |
// comment | /* comment */ | Use /* */. | CSS |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
int data[1]; data[1]=5; | int data[1]; if(1<1){{}} else data[1]=5; | Bounds check. | C++ |
SELECT age email FROM orders; | SELECT age, email FROM orders; | Add comma. | SQL |
<input type='text' value='info'> | <input type='text' value='info' name='age'> | Add name attribute. | HTML |
test | test() | Add parentheses. | Kotlin |
UPDATE items SET email='info' WHERE email=71 | UPDATE items SET email='info' WHERE email=71; | Add semicolon. | SQL |
if (b = 16) {{}} | if (b === 16) {{}} | Use === for equality. | JavaScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.